Fatal error: Call to undefined function mysql_connect() in C:\Apache\htdocs\test.php on line 2
I've spent 11 hours today trying to get past this ONE problem.
I have installed: MySQL 5.1 Apache 2.2.14 PHP 5.2.17
these were the versions referred to in the book "PHP and MySQL".
When I run the script:
<?php
mysql_connect ('localhost', 'root', 'password');
?>
where localhost, root and password are the REAL values for this given test system and all I have seen is:
Fatal error: Call to undefined function mysql_connect() in C:\Apache\htdocs\test.php on line 2
Uncomment the line extension=php_mysql.dll
in your "php.ini" file and restart Apache.
Additionally, "libmysql.dll" file must be available to Apache, i.e., it must be either in available in Windows systems PATH or in Apache working directory.
See more about installing MySQL extension in manual.
P.S. I would advise to consider MySQL extension as deprecated and to use MySQLi or even PDO for working with databases (I prefer PDO).
I had the similar issue. I solved it the following way after a number of attempts to follow the pieces of advice in the forums. I am reposting the solution because it could be helpful for others.
I am running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file "httpd.conf" (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) was sensitive to slashes. You can check if "php.ini" is read from the right directory. Just type in your browser "localhost/index.php". The code of index.php is the following:
<?php
echo phpinfo();
?>
There is the row (not far from the top) called "Loaded Configuration File". So, if there is nothing added, then the problem could be that your "php.ini" is not read, even you uncommented (extension=php_mysql.dll and extension=php_mysqli.dll). So, in order to make it work I did the following step. I needed to change from
PHPIniDir 'c:\PHP\'
to
PHPIniDir 'c:\PHP'
Pay the attention that the last slash disturbed everything!
Now the row "Loaded Configuration File" gets "C:\PHP\php.ini" after refreshing "localhost/index.php" (before I restarted Apache2.2) as well as mysql block is there. MySQL and PHP are working together!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With