PDA

View Full Version : mysql_connect()


bobo
1-13-05, 02:33 AM
I just installed mysql4.1.8 and php 5.03 on windowxp. I made a simple code to connect to mysql server, but I didnot work.Here is the error message and the code:
Fatal error: Call to undefined function mysql_connect() in d:\Inetpub\wwwroot\mysqltest.php on line 4

<html>
<head>
<body>
<?php
$linkID = mysql_connect("localhost","root","911");
if ($linkID != FALSE)
{ echo 'successfully';}
else
{ echo 'failed'; }
mysql_close($linkID);
?>


</body>
</html>

det1smc
1-13-05, 02:39 AM
Look at your php info page and see if mysql is enabled:

<html>
<head>
<body>
<?php
echo phpinfo();
?>
</body>
</html>


I don't think mysql enabled by default in php5, not sure about that...

det1smc
1-13-05, 02:54 AM
sure enough... (http://us3.php.net/manual/en/ref.mysql.php)

In PHP 5, MySQL is no longer enabled by default, nor is the MySQL library bundled with PHP. Read this FAQ for details on why.

Note: Windows users will need to enable php_mysql.dll inside of php.ini and either copy libmysql.dll into the Windows system directory, or make it available to the PATH.

This will fix "Unable to load dynamic library './php_mysql.dll'" errors.

For compiling, simply use --with-mysql=[DIR] where [DIR] points to your MySQL installation directory.


If you don't plan on running your scripts from a powweb server in the near future... you should use the mysqli extension instead of mysql.

riskynil
1-13-05, 12:05 PM
Boy, howdy, I know exactly the problem you're facing. =) I recently upgraded to PHP 5 and suffered the same issues. This are the changes I made to make them work:

In php.ini, I had to add these two lines:
extension=php_mysql.dll
extension=php_mysqli.dll

(I'm setting it up so both the mysql_* functions and mysqli_* functions will work.)

In the httpd.conf for Apache, I added these two lines:
LoadFile C:/php/libmysql.dll
LoadFile C:/php/libmysqli.dll

I added them right before the line of:
LoadModule php5_module c:/php/php5apache2.dll

Then make sure you have a copy of libmysql.dll, libmysqli.dll, php_mysql.dll, and php_mysqli.dll in the correct directory. (I put all of them in my main php directory.)

Also, this doesn't apply to you, but for anyone who unfortunately upgraded to PHP 5.0.2 on Windows--such as myself--an old API was bundled into that version and it'll display errors if you use the mysql_* functions. You'll have to pick up the PHP 5.0.3 version to get the new API. That little problem is ONLY associated with the Windows binary version of PHP 5.0.2, however, not other systems or versions.

Happy trails!

-- Ryan