Page 1 of 1
mysql_connect() Undefined Function
Posted: Tue Dec 01, 2009 5:55 pm
by sheppardzwc
Hey, I recently installed PHP v5.2.11 on my computer. (Windows XP Pro SP3) I downloaded the pre-compiled version (since I have no idea how to compile it on Win) and just finished my database class script, when I get this:
Fatal error: Call to undefined function mysql_connect() in C:\tg\includes\class.db.php on line 38
I thought ok, I'm a beginner at OO PHP, maybe I screwed something up in there. So I wrote a simple PHP file to connect and ran it on the command line (php "test.php") and it gave me the same error.
C:\www\php5211>php -version
PHP 5.2.11 (cli) (built: Sep 16 2009 19:39:46)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
I looked in the .ini file and didn't see anything to enable it or something.. so do I need to compile this version myself?
Re: mysql_connect() Undefined Function
Posted: Tue Dec 01, 2009 6:03 pm
by John Cartwright
In PHP5, by default, mysql extension is not enabled. Locate your php.ini (path exposed through phpinfo()), and remove the ; at the beginning of the mysql.dll or mysql.so extension, and finally restart apache.
Re: mysql_connect() Undefined Function
Posted: Tue Dec 01, 2009 6:05 pm
by sheppardzwc
John Cartwright wrote:In PHP5, by default, mysql extension is not enabled. Locate your php.ini (path exposed through phpinfo()), and remove the ; at the beginning of the mysql.dll or mysql.so extension, and finally restart apache.
I looked and did not find it. In fact, I don't even have an \ext folder where the extensions are normally stored. (I'm on Windows, so it's .dll files)
I just googled and found a guide to compile PHP on Windows, so I might try that instead, but a fix is still appreciated if this doesn't work.
Re: mysql_connect() Undefined Function
Posted: Tue Dec 01, 2009 6:07 pm
by John Cartwright
Again, create a file with only
in it, which will tell you exactly where your loaded php.ini is located.

Re: mysql_connect() Undefined Function
Posted: Tue Dec 01, 2009 7:07 pm
by sheppardzwc
John Cartwright wrote:Again, create a file with only
in it, which will tell you exactly where your loaded php.ini is located.

No, I didn't find the ";mysql.dll." Sorry, didn't mean to confuse you. I know where the .ini file is. :p
Re: mysql_connect() Undefined Function
Posted: Tue Dec 01, 2009 7:41 pm
by John Cartwright
Oops, it's actually called php_mysql.dll (not just mysql.dll). Give that a shot.
Re: mysql_connect() Undefined Function
Posted: Tue Dec 01, 2009 7:53 pm
by sheppardzwc
John Cartwright wrote:Oops, it's actually called php_mysql.dll (not just mysql.dll). Give that a shot.
I decided I'd just uninstall the windows-installed PHP and use the zip package. It included all the ext\'s and it gave me a better experience in configuring it. Thank you for your help though John, much appreciated. (I'll use
http://php.net/mysql from now on hehe)
If anyone needs this, here you go;
http://www.thesitewizard.com/php/instal ... dows.shtml
Re: mysql_connect() Undefined Function
Posted: Wed Dec 02, 2009 7:41 am
by sheppardzwc
Bah. I spoke too soon. I'm still having the issue.
My php.ini is as follows; (only extensions, if you need the whole copy, just ask)
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
extension=libmysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
extension=php_zip.dll
Does anyone know how to fix this?
Re: mysql_connect() Undefined Function
Posted: Wed Dec 02, 2009 1:23 pm
by John Cartwright
So whats the issue now? The extension exists in the extension folder, you removed the comment character for php_mysql.dll, but have you restarted apache?
If so, check your error logs which should tell you why the extension failed to load.
Re: mysql_connect() Undefined Function
Posted: Wed Dec 02, 2009 1:31 pm
by AbraCadaver
You probably either need to add your PHP directory to your path var or copy the mysql.dll (NOT php_mysql.dll) from the PHP dir to windows\system or windows\system32. Then restart apache. This is how I had to do it in the past but I haven't used windows in a while.
-Shawn
Re: mysql_connect() Undefined Function
Posted: Wed Dec 02, 2009 2:52 pm
by sheppardzwc
AbraCadaver wrote:You probably either need to add your PHP directory to your path var or copy the mysql.dll (NOT php_mysql.dll) from the PHP dir to windows\system or windows\system32. Then restart apache. This is how I had to do it in the past but I haven't used windows in a while.
-Shawn
Don't got enough money for a Linux VPS or Dedicated right now is why I'm using Windows. And it's a pain in the ass. But eh.
John Cartwight wrote:So whats the issue now? The extension exists in the extension folder, you removed the comment character for php_mysql.dll, but have you restarted apache?
If so, check your error logs which should tell you why the extension failed to load.
The extension_dir setting was set to "./" and all my extensions were located in the ext folder, so I changed it to "./ext" and it works perfectly now. Had to look in the apache logs to find it. Thanks.
