Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

PHP MYSQL Error 500

I'm having an error 500 connecting to my localhost database,
Code
<?php
try{
    // Create connection
    $conn = new mysqli("localhost", "username", "password");
}catch(Exception $e){
    echo $e;
}
echo "Connected successfully";
?>
Unfortunately, I never get an error report instead it just returns error 500 in browser
What is the cause of this error?
Check your error log . This ain’t enough
The issue is that when I check the error logs it is empty?
Is there somewhere else that the error logs are located?
turn on error logging display, temporarily:

ini_set('display_errors', 1);
(Jul 18, 2019 04:02 PM)Jack Drake Wrote:  The issue is that when I check the error logs it is empty?
Is there somewhere else that the error logs are located?

Check you vhost conf, you should have the path to your logs if everything was correctly setup.
Something like this:
Code
ErrorLog /var/log/error.log
LogLevel warn
CustomLog /var/log/access.log combined
[Image: vibesignature.gif]


“Whatever Your Mind Can Conceive and Believe, It Can Achieve.” – Napoleon Hill
Thanks a lot for your help guys, Thankfully I was able to found that the error was that the mysqli class couldnt be found:
Code
Fatal error: Uncaught Error: Class 'mysqli' not found in /var/www/html/database/connect.php:4 Stack trace: #0 {main} thrown in /var/www/html/database/connect.php on line 4

I found a couple sources suggesting that i enable the mysqli extension in php.ini.
Unfortunately the same error appears when I enable it.

How can I install the mysqli class?
you can install it by "sudo apt install php7.2-mysqli"
and then restart the server with "sudo service apache2 restart"
(Jul 21, 2019 01:06 PM)Jack Drake Wrote:  Thanks a lot for your help guys, Thankfully I was able to found that the error was that the mysqli class couldnt be found:
Code
Fatal error: Uncaught Error: Class 'mysqli' not found in /var/www/html/database/connect.php:4 Stack trace: #0 {main} thrown in /var/www/html/database/connect.php on line 4

I found a couple sources suggesting that i enable the mysqli extension in php.ini.
Unfortunately the same error appears when I enable it.

How can I install the mysqli class?

Don't forget to restart your web server after enabling mysqli.
/* No comment */
I used to get this a lot, I never understood why I would get it.

What company are you hosting your server on?
check if mysqli extension enabled in php.ini uncomment it
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
I got the same error about one week ago, it was because I had the header set wrong, like this:
header("Location : index.php");
the problem is that space between Location and :
(Aug 27, 2019 11:24 AM)FoxBlood Wrote:  I got the same error about one week ago, it was because I had the header set wrong, like this:
header("Location : index.php");
the problem is that space between Location and :
Dude this makes no sense. It's a MySQL error, nothing to do with PHP. Instead of offering useless and irrelevent information, read the thread next time.

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
I'd suggest re-writing this to include some error handling. Here's an example including some comments:

PHP Code

<?php
// Start by defining your SQL database information as variables (best practice)
$db = "localhost";
$username = "username";
$password = "password";

// Create the connection
$conn = new mysqli($db, $username, $password);
// Check the connection
if ($conn->connect_error) {
 
   die("Database connection failed: " . $conn->connect_error);  // return this if we could not connect
} 

// Execute your query or any other code in this space, for example lets create a database
$sql = "CREATE DATABASE newDatabase";
if (
$conn->query($sql) === TRUE) {    // if there are no errors connecting/executing the query
 
   echo "Database created successfully";
} else {
 
   echo "Error creating database: " . $conn->error; //otherwise return an error
}

$conn->close();  // close the connection
?>
Sidenote: this thread is more than a month old, probably was bumped up for post count increase.
You see, Doctor, God didn't kill that little girl. Fate didn't butcher her and destiny didn't feed her to those dogs.
If God saw what any of us did that night he didn't seem to mind. From then on I knew... God doesn't make the world this way.
We do.
(Aug 29, 2019 03:14 PM)helios Wrote:  I'd suggest re-writing this to include some error handling. Here's an example including some comments:

PHP Code

<?php
// Start by defining your SQL database information as variables (best practice)
$db = "localhost";
$username = "username";
$password = "password";

// Create the connection
$conn = new mysqli($db, $username, $password);
// Check the connection
if ($conn->connect_error) {
 
   die("Database connection failed: " . $conn->connect_error);  // return this if we could not connect
} 

// Execute your query or any other code in this space, for example lets create a database
$sql = "CREATE DATABASE newDatabase";
if (
$conn->query($sql) === TRUE) {    // if there are no errors connecting/executing the query
 
   echo "Database created successfully";
} else {
 
   echo "Error creating database: " . $conn->error; //otherwise return an error
}

$conn->close();  // close the connection
?>
2019 and suggesting anything but PDO.... ok


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by AlexFeb 10, 2020 03:51 PM 2 170 Feb 10, 2020 03:51 PM
Last Post: Alex
[PHP] by Jack DrakeApr 5, 2019 03:32 AM 12 288 Apr 5, 2019 03:32 AM
Last Post: xHeaven
[PHP] by HoneybunMay 10, 2018 11:52 AM 5 158 May 10, 2018 11:52 AM
Last Post: Honeybun