Forum Moderators: coopster

Message Too Old, No Replies

mysql connection thru php

win xp sp2, mysql-5.0.18, php-5.1.1

         

alkuma

11:27 am on Feb 23, 2006 (gmt 0)

10+ Year Member



I'm trying to connect to the mysql database via a php script.
Here's my setup:

win xp sp2
Apache2 up and running
php 5.1.1

apache to php connection:
the apache httpd.conf file contains
LoadModule php5_module "C:\php\php5apache2.dll"
<IfModule mod_mime_magic.c>
MIMEMagicFile conf/magic
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
Action application/x-httpd-php "/php/php-cgi.exe"
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php-cgi.exe"
SetEnv PHPRC C:/php
PHPIniDir "C:\php\"

So apache knows about the php setup.

php to mysql connection
mysql is running at port 3306 - via mysqld --console
There is a root user which can connect to mysql via "mysql".

php.ini is present in c:\php and it contains:
extension_dir = "c:\php\ext"
extension=php_mysql.dll

[MySQL]
mysql.allow_persistent = On
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off

So Apache knows about php, and php knows about mysql

Now, apache is up and mysqld is up.

When I run this script to connect to the database,
<php
$username = "<whatever>";
$password = "<whatever>";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to Mysql");
print "Connected";
?>

I get the error

Fatal error: Call to undefined function mysql_connect() in D:\htdocs\mysql.php on line x

which means that php is not able to identify the mysql extension.

What do I need to do?

coopster

5:04 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



PHP needs access to the MySQL client library. A file named
libmysql.dll
is included in the Windows PHP distribution and in order for PHP to talk to MySQL this file needs to be available to the Windows systems PATH. See the FAQ titled "How do I add my PHP directory to the PATH on Windows [php.net]" for information on how to do this. Although copying
libmysql.dll
to the Windows system directory also works (because the system directory is by default in the system's PATH), it's not recommended.

Resource: MySQL Functions [php.net]

alkuma

3:58 am on Feb 24, 2006 (gmt 0)

10+ Year Member



coopster, thanks for your reply.

Now, I have two of these libmysql.dll's.

One, that comes with php - size 1 069 056
Another, that comes with mysql - size 1 302 528

Which one of these should be in the path?
I'll anyway try both, one by one.

Thanks again.

alkuma

4:29 am on Feb 24, 2006 (gmt 0)

10+ Year Member



ok, adding the path of the first one (C:\php) didn't work. I'm trying the second one now.

alkuma

8:58 am on Feb 24, 2006 (gmt 0)

10+ Year Member



and, for your information, adding the second path didn't work either.
I'm running out of options to explore. Any help will be appreciated.

coopster

4:35 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't know where to point you except for another troubleshooting thread ...

[webmasterworld.com...]

henry0

5:02 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I assume that you are trying to instell a test bed on a Windows machine.
if so did you copy the MySQL DLLs releated to the root of apache2?

henry0

1:15 pm on Feb 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not stay here

we have Our Own Tutorial! [webmasterworld.com]

orion_rus

5:27 pm on Feb 25, 2006 (gmt 0)

10+ Year Member



Try to search php.ini for extensions see if
php_mysql.dll is uncommented if not so uncomment it and reload your apache server

alkuma

11:31 am on Feb 27, 2006 (gmt 0)

10+ Year Member



did you copy the MySQL DLLs releated to the root of apache2?

The mysql dll's are currently located at
c:\php\ext
and
c:\php

but that has no effect.
Should they present in any other location as well?

Sorry I didn't understand what is meant by "to the root of apache2" - Do you mean the
C:\Program Files\Apache Group\Apache2\bin
directory?
Or some other?

alkuma

11:58 am on Feb 27, 2006 (gmt 0)

10+ Year Member



ok - the mysql function not found issue is solved - The ini file present in c:\windows was being picked up and c:\php was not being recognized as a location for php.ini. I have currently copied the php.ini file to c:\windows to resolve this issue.

Thanks to everybody for the help.
Hope I'll be in a position to ask more questions now that I have the setup ready - and eventually be able to help others too.

coopster

2:18 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yep, that's a common installation issue. Message # 19 of the troubleshooting thread I mentioned earlier explains exactly how that works. Glad you got it sorted.