1

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?

2 Answers 2

1

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-rich mysql.

You have 2 choices:

1) Update your code to use mysqli_* functions

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

1
  • That did it. Thanks for the solution and providing some options.
    – Chris Hart
    Jun 19, 2011 at 18:01
0

maybe you can try this:

In file php.ini has been uncommented extension mysql.so? or try con this post

I hope it solves your problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .