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 ($db->connect_errno()) {
    printf("Connect failed: %s\n", $db->connect_error());
    exit();
}

When i remove it the page loads fine. How can i fix it?

Tural Ali
  • 22,202
  • 18
  • 80
  • 129
  • 3
    Your web server should have an error log containing more detailed information about the nature of the error. – Pekka Aug 09 '11 at 07:45
  • i can't find log files of webmatrix server – Tural Ali Aug 09 '11 at 07:47
  • 2
    Then you'll need to find out where and how the server logs errors. I don't think anybody will be able to help you without the exact error message - it could be anything – Pekka Aug 09 '11 at 07:49

2 Answers2

5

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

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

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.

FrankS
  • 2,374
  • 3
  • 26
  • 32