I have compiled PHP 5.3.6 from source on Mac OS X 10.6 using the –with-mysqli=mysqlnd option. The output of both php -m and php-cgi -m show the mysqli and mysqlnd modules. When I run a simple test PHP file containing a mysql_connect(…) using the regular php binary, it connects fine. When I use the same test PHP file with php-cgi, I get:
PHP Fatal error: Call to undefined
function mysql_connect() in
/Users/chris/test2.php on line 2
I've confirmed that the MySQL socket information is correct in php.ini and have ensured that php-cgi is using that file using the -c argument. MySQL works fine using the regular mysql command line interface and obviously is working with regular PHP. phpinfo() from php-cgi shows correct versions of mysqli & mysqlnd libraries.
I need to run PHP in a CGI configuration in this particular environment so I really need php-cgi to work. I am not worried about Apache2/nginx/etc at this point – just getting CGI to work. Any advice on what I am missing?
Best Answer
You have compiled PHP with support of mysqli extension (mysqli_* functions)... but the error clearly shows that you are using
mysql_connect()
function (without "i", which belongs to mysql extension). These are 2 different extensions:mysqli
stands for "MySQL Improved" and is preferred to use over older and less feature-richmysql
.You have 2 choices:
1) Update your code to use
mysqli_*
functions2) Compile your PHP again with
mysql
extension support (do not forget to enable it later in php.ini)P.S. In any case I would recommend to use PDO for your database needs (if you can, of course).