Getting HTTP Error 500.0
My system is Windows XP SP2 and my weserver is Microsoft Webmatrix. PHP works well but when i'm trying to add db connection it gives http Error 500.0. The piece of code that issues error
$db = new MySQLi('localhost', 'my_login', 'my_pass', 'db_name');
if ($d开发者_如何学Gob->connect_errno()) {
printf("Connect failed: %s\n", $db->connect_error());
exit();
}
When i remove it the page loads fine. How can i fix it?
mysqli::connect_errno
and mysqli::correct_error
are properties, not functions:
$db = new MySQLi('localhost', 'my_login', 'my_pass', 'db_name');
if ($db->connect_errno) {
printf("Connect failed: %s\n", $db->connect_error);
exit();
}
Your PHP will be producing an error because of this, and you have display_errors
turned off so it's just getting chucked into the server log and a general 500 error presented to the user.
You should also heed the note in the documentation that says:
The mysqli->connect_error property only works properly as of PHP versions 5.2.9 and 5.3.0.
Are you using PHP version 5.2.9 or 5.3.0 or later?
You must find your server logs to perform fault diagnoses in the future.
According to Wikipedia, Microsoft WebMatrix is a software bundle which uses IIS Express for webserver functionality. Looking up where IIS Express stores its logs leads us to this Q&A; look for a directory named "IISExpress" in your user directory (or in that of the system administrator account).
Error Code 500 means there is an internal server error - usually this means some server configuration is wrong. Wikipedia has an overview about all http status codes. As others already mentioned: It is hard to help you without taking a look at the error logs. I would also make sure, that the db credentials are correct.
精彩评论