Windows + PHP 5.3.6 - Undefined function, mysql_connect?
We have a brand new webserver upon which we installed Apache, then PHP, pointing it to Apache's conf dir, and installing all of the optional pieces. I'm now trying to get MySQL to connect, and it refuses. My PHP.ini lists the module as uncommented, and it is in the directory my extension dir is set to, but I just keep getting:
Fatal error: Call to undefined function mysql_connect()开发者_运维知识库 in C:\apache\htdocs\index.php on line 8
I installed:
PHP: VC9 x86 Thread Safe (2011-Mar-22 13:27:32)
Apache: Apache 2.2
MySQL: Windows (x86, 64-bit), MSI Installer
Windows: Windows 7
I've added PHP to my PATH var, and have phpinfo() outputting, but I'm not sure what to look for. All of the docs I've read seem to indicate that in PHP 5.3.x+ MySQL / MySQLi support should be enabled by default.
phpinfo's mysqlnd info:
mysqlnd
mysqlnd enabled
Version mysqlnd 5.0.8-dev - 20102224 - $Revision: 308673 $
Compression supported
SSL supported
Command buffer size 4096
Read buffer size 32768
Read timeout 31536000
Collecting statistics Yes
Collecting memory statistics No
Tracing n/a
phpinfo's configure command info:
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--disable-isapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=D:\php-sdk\oracle\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet" "--with-mcrypt=static"
phpinfo's loaded config file info:
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File C:\Program Files (x86)\PHP\php.ini
Inside of that, towards the bottom:
[dba]
;dba.default_handler=
; Local Variables:
; tab-width: 4
; End:
[PHP_BZ2]
extension=php_bz2.dll
[PHP_CURL]
extension=php_curl.dll
[PHP_FILEINFO]
extension=php_fileinfo.dll
[PHP_GD2]
extension=php_gd2.dll
[PHP_GETTEXT]
extension=php_gettext.dll
[PHP_GMP]
extension=php_gmp.dll
[PHP_IMAP]
extension=php_imap.dll
[PHP_INTL]
extension=php_intl.dll
[PHP_LDAP]
extension=php_ldap.dll
[PHP_MBSTRING]
extension=php_mbstring.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_OPENSSL]
extension=php_openssl.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
[PHP_PDO_ODBC]
extension=php_pdo_odbc.dll
[PHP_PDO_SQLITE]
extension=php_pdo_sqlite.dll
[PHP_PGSQL]
extension=php_pgsql.dll
[PHP_SOAP]
extension=php_soap.dll
[PHP_SOCKETS]
extension=php_sockets.dll
[PHP_SQLITE]
extension=php_sqlite.dll
[PHP_SQLITE3]
extension=php_sqlite3.dll
[PHP_TIDY]
extension=php_tidy.dll
[PHP_XMLRPC]
extension=php_xmlrpc.dll
[PHP_EXIF]
extension=php_exif.dll
EDIT: So I played around with my .ini a bit, deleting it, putting junk in it, and phpinfo() kept the same info. So I actually looked hard, and I have my .ini set upload_max_filesize
to 200M, but phpinfo says 2M. What gives? It's the exact file that phpinfo is trying to tell me is the .ini.
It turns out there was a parse error in the config file due to the paren in Program Files (x86) not being enclosed with quotes. Great call by Charles to suggest starting PHP from the command line!
Most common mistake (particularly on Windows) is to forget setting up the path of "extension_dir" in the php.ini file. PHP by default assumes C:\php\ext, whereas many prefer to unzip PHP to C:\Program Files\PHP.
精彩评论