While connecting to mysql server using php displaying http 500 error

Hi i am relatively new to PHP and Mysql, i have configured PHP on IIS 6 and i am able to connect to mysql using command prompt but when i try to connect using mysqli_connect in PHP code i am getting HTTP 500 error. Can somebody help me out please.

A 500 error is normaly due to lack of permisions or wrong password/username… basically, you’re forbidden to access a particular directory. This error is more related to the web server and not to MySQL so you should check your IIS configuration.

Particularly, make sure that the folder where you’re keeping your php files is public for the web server (has at least read/execute permisions)

Hi Molona thanks for the reply i am running mysql sever on different port other than default port and i am currently running it on 4242 should i specify localhost:4242 as parameter in the mysqli_connect…?
Thanks shree,

That will definately help! :smiley:

Hi Malona i tried reconfiguring mysql and set the port number to default still no solution at all. Should i change php.ini configuration…? if i use phpinfo() web browser opens the PHP info page with all details. What could be wrong…? i am using default username “root” sor connecting to mysql DB

If your PHP is working and you can see the page, then IIS is rightly configured and that may be the case… although I would expect something different than a 500 error.

A 500 error is a HTTP error, no expecifically a database connection error… but it may be the page don’t know how to deal with this. But when I see a 500 I tend to think that the web server has not been configured to read certain files and folders.

As you say, it may be that you need to change you php.ini to tell php where the extensions are and, to be precise, where the mysql dll is foun d (php_MySQL.dll is normally in the extensions folder, the the line

extension_dir = "C:/PHP/ext/"

to point where the php extensions are…
Also make sure that the server line points to the right folder, as an example

IIS doc_root "c:\\Inetpub\\wwwroot"

Also, make sure that the IIS user (usually IUSR_MACHINENAME) needs permission to read various files and directories, such as php.ini, docroot, and the session tmp directory.

Hello,

When you are going troubleshooting a HTTP 500 error with PHP can be a small piece of a can of worms. So much of it depends on things exact to your local environment, such as what Windows operating system you are using, how you have the PHP application mapping configured in IIS, under what security background your IIS application is run and even your php.ini configuration. In this article we’ll look at some common causes of what can cause a HTTP 500 error in your PHP environment.

verify you PHP application mapping and make sure that the path to you PHP handler is set properly. If you are applying FastCGI you will also want to check that the correct path is specified in the registry (if using the community version of FastCGI) or in fcgiext.ini (if using MS FastCGI)

Make sure the application mapping extension is the same as the actual scripts you are trying to run. For example the application mapping is .php, make sure you php scripts are using the .php extension.

Thanks Malona u have been a great source of help for me. Thanks Casius as well for ur keenness on helping me out. Guys i nailed the problem, the problem was php\ext\ directory didn’t had PHP_mysql.dll link library. The problem is i downloaded the latest version of PHP archive and extracted it but it didnt had the ext directory and the above mentioned dll is directly residing in PHP directory later i had created EXT directory in the PHP directory and downloaded the PECL package and extracted all the dll to EXT directory. but the php_mysql.dll was not there in the PECL package i downladed so since browser was not able to locate the php_mysql.dll in the EXT directory it was giving http 500 error. I copied the php_mysql.dll from PHP diectory to EXT directory and it workrd :smiley: :lol:
Malona Thanks again.

You’re welcome. I’m glad that you could sort your problem out and that now everything is working properly :slight_smile: