mysqli compilation woes
This article was written at a time when PHP5 was still tagged as a beta.
Installing PHP 5 With mySQLi
Hope you read my recent article about installing PHP5. The installation went smoothly, but a call to phpinfo() revealed that the new improved mysql extension (mysqli) has not been automatically installed as I had assumed. The documentation says your configuration command has to include it using the --with-mysqli directive. So the configure script had to be changed as follows.
./configure --enable-xslt --with-xslt-sablot
--with-gd --with-zlib --without-mysql
The configuration step ran to completion but the same cannot be said about the 'make'. The compilation had quite a few problems and suprising Google didn't seem to know much about it either. The normal practice of pasting the error message on google didn't bring up any clues.
/opt/php-5.0.0b3/ext/mysqli/mysqli_api.c: In function `zif_mysqli_bind_param':
/opt/php-5.0.0b3/ext/mysqli/mysqli_api.c:177: structure has no member named `sqlstate'
/opt/php-5.0.0b3/ext/mysqli/mysqli_api.c: In function `zif_mysqli_bind_result':
/opt/php-5.0.0b3/ext/mysqli/mysqli_api.c:317: structure has no member named `sqlstate'
opt/php-5.0.0b3/ext/mysqli/mysqli_api.c:1827: `MYSQL_OPTION_MULTI_STATEMENTS_OFF' undeclared (first use in this function)
/opt/php-5.0.0b3/ext/mysqli/mysqli_api.c: In function `zif_mysqli_use_result':
/opt/php-5.0.0b3/ext/mysqli/mysqli_api.c:1880: structure has no member named `sqlstate'
/opt/php-5.0.0b3/ext/mysqli/mysqli_api.c:1881: `MYSQL_OPTION_MULTI_STATEMENTS_OFF' undeclared (first use in this function)
Directory browsing with PHP.|
Perl Mysql and Blobs
Image upload and resize with PHP.
When STFW fails, the next step usually is to try to grep the header files to see if any of these constants have been defined in some header that is not in the include path. Turned out to be another wild goose chase.
Fortunately there is yet another resource that you can turn to when having trouble with php. That is the user contributed annotations in the PHP manual at php.net . Seems that I am not the only one to have faced this problem, someone had commented that though the docs say mysql 4.1.0 is needed the actual fact is the mysqli functions need mysql 4.1.1 to work.
After another revisit to mysql.com, downloading and installing mysql 4.1.1 looks like I still haven't found the cure since make now has a fresh set of error messages.
/opt/php-5.0.0b3/ext/mysqli/mysqli_report.c: In function `php_mysqli_report_index':
/opt/php-5.0.0b3/ext/mysqli/mysqli_report.c:64: `SERVER_QUERY_NO_GOOD_INDEX_USED' undeclared (first use in this function)
/opt/php-5.0.0b3/ext/mysqli/mysqli_report.c:64: (Each undeclared identifier is reported only once
/opt/php-5.0.0b3/ext/mysqli/mysqli_report.c:64: for each function it appears in.)
/opt/php-5.0.0b3/ext/mysqli/mysqli_report.c:66: `SERVER_QUERY_NO_INDEX_USED' undeclared (first use in this function)
Google wasn't very familiar with this one either. But fortunately it had a reference to an archived mailing list message at: http://lists.mysql.com/internals/11192 . This message included a patch that had the appropriate definitions for the two constants SERVER_QUERY_NO_GOOD_INDEX_USED, and SERVER_QUERY_NO_INDEX_USED
#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
#define SERVER_QUERY_NO_INDEX_USED 32
The new run of configure, make and make install seemed go smoothly and after a restart phpinfo() tells me that the mysqli module has finally been enable. But it comes at a cost. The older mysql api is no longer available.
Unfortunately making the two modules work side by side seems a very complicated tasks and according to the documentations the mysql extention does not seem to work with the more recent versions of mysql (newer than 4.1.0). But all is not lost it seems from the function list that if we replace all occurrences of mysql_ with mysqli_ in our code it should work with the newer api?
I will post a follow up to this article after trying it out
Though the manual says the older mysql api does not work with mysql 4.1+ it does!