Hack Forums
[PHP] PHP MYSQL Error 500 - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] PHP MYSQL Error 500 (/showthread.php?tid=5991025)

Pages: Pages 1 2


PHP MYSQL Error 500 - Jack Drake - Jul 18, 2019

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?


RE: PHP MYSQL Error 500 - Charger - Jul 18, 2019

Check your error log . This ain’t enough


RE: PHP MYSQL Error 500 - Jack Drake - Jul 18, 2019

The issue is that when I check the error logs it is empty?
Is there somewhere else that the error logs are located?


RE: PHP MYSQL Error 500 - MaxiPads889 - Jul 18, 2019

turn on error logging display, temporarily:

ini_set('display_errors', 1);


RE: PHP MYSQL Error 500 - newQuery - Jul 19, 2019

(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



RE: PHP MYSQL Error 500 - Jack Drake - Jul 21, 2019

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?


RE: PHP MYSQL Error 500 - Abruptum - Jul 23, 2019

you can install it by "sudo apt install php7.2-mysqli"
and then restart the server with "sudo service apache2 restart"


RE: PHP MYSQL Error 500 - Quad - Jul 24, 2019

(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.


RE: PHP MYSQL Error 500 - Proxies - Aug 26, 2019

I used to get this a lot, I never understood why I would get it.

What company are you hosting your server on?


RE: PHP MYSQL Error 500 - HFDone - Aug 26, 2019

check if mysqli extension enabled in php.ini uncomment it


RE: PHP MYSQL Error 500 - FoxBlood - Aug 27, 2019

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 :


RE: PHP MYSQL Error 500 - Nachfolger - Aug 27, 2019

(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.


RE: PHP MYSQL Error 500 - helios - Aug 29, 2019

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
?>



RE: PHP MYSQL Error 500 - Squito - Aug 30, 2019

Sidenote: this thread is more than a month old, probably was bumped up for post count increase.


RE: PHP MYSQL Error 500 - Charger - Aug 30, 2019

(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