Monday, June 15, 2009

Fatal error: Call to undefined function mysql_connect()

Well, I've long time not used PHP, and now I am back.

I installed the newest Apache, the newest PHP, the newest Mysql, and everything is smooth. Seems the UIs are much better than 4 years ago. I took pretty caution to the PHP configuration, and choosed to install mysql support at beginning, so everything seems ok at first.

But I met issue soon. When I call mysql_connect, it immediately says:

Fatal error: Call to undefined function mysql_connect() ...

As I am experienced engineer, I don't worry about this, checked all website for this issue, but everyone just repeatedly saying: check your php.ini file to remove the semicolon before the line of extension=php_mysql.dll, or check your extension_dir setting to make sure it's correct, something like that, blah, blah, blah... I checked again at my php.ini setting, it's pretty correct, because when I install php I already choose to have mysql support installed, so everything already correctly setting for me. I tried many other ways, to copy php.ini file into windows folder, to copy php_mysql.dll into windows folder, and also tried windows system32 folder, and also checked the environment variable of PHPRC, the problem just still be there.

Finally I got the problem solved. Now let me tell you the truth, this IS the exactly quite important step, but the PHP installation program did not do it correctly.

Very simple, that is: to copy the file libmysql.dll from your PHP folder into Windows folder. Very simple, right? But that's it.

Now we know, there are 3 files related to mysql support in php:

1. libmysql.dll (this by default is in ext folder, you can leave it there)
2. php_mysql.dll (this be default is in your php folder, you need to manually copy it into windows folder)
3. php.ini (this by default is in your php folder, you can leave it there)

You made them in correct folder, you got it.

No comments: