PDA

View Full Version : PHP, Apache, and MySQL



Captain_Thunder
December 30th, 2005, 10:47
From what I understand, this is a common problem: getting PHP to work with MySQL. In the php.ini file located at C:\WINDOWS, I have the line extension=php_mysql.dll, and it is uncommented. And the extension dir is set to where all extensions are located. And the file libmysql.dll is in the C:\WINDOWS folder. When I look at the results of the phpinfo() function, I see a section of data pretaining to MySQL, so I know PHP sees it. Yet I still cannot connect to MySQL. The only thing I can think of is that Apache is installed to a different directory than MySQL; could that affect anything? Must Apache be configured to use MySQL in addition to PHP? I am using PHP5, MySQL4, and Apache2.2 if that helps. How do I get PHP to connect to my database?

Tree
December 30th, 2005, 11:11
I have never installed PHP, Apache, or MySQL on a Windows server, so my future answers may be way off.

What version of MySQL do you have? 4.1(+) or 4.0(-)?

Tree
December 30th, 2005, 11:26
If you have MySQL 4.0 or earlier, you have it right as
extension=php_mysql.dll

But if you have MySQL 4.1 or later, you need to have
extension=php_mysqli.dll

Captain_Thunder
December 30th, 2005, 11:57
No, that didn't do it. Is there anyway to "restart" PHP? Like with Apache, you have to restart it for any canges in the config file to take affect.

Tree
December 30th, 2005, 12:04
No, PHP isn't really a "service", like Apache and MySQL are. PHP is just an extension to Apache, so restarting Apache will restart PHP.

Do you have php_mysql.dll or php_mysqli.dll in the ext subdirectory in the directory where PHP is installed?

Captain_Thunder
December 30th, 2005, 12:19
Yes, both of them are in there. Should I be loading both of them?

Tree
December 30th, 2005, 12:26
No, you should delete the one that you aren't using. What MySQL version do you have?

Captain_Thunder
December 30th, 2005, 12:28
I think I found something:
With the mysqlc utility, when I type "connect test [myIPaddress]", it says "host cannot connect to the database". But when I sustitute my IP address with localhost, it connects fine. Does anyone know what this might mean?

Captain_Thunder
December 30th, 2005, 12:29
No, you should delete the one that you aren't using. What MySQL version do you have?
4.0.21

Tree
December 30th, 2005, 12:33
That would mean that you didn't configure your IP address correctly. Go back into your httpd.conf (If you have a version of Apache earlier than 2.0) and find

BindAddress
Make sure that the IP address you're trying to connect to is correctly set in there.

If you have 2.0 or later, find Listen and set it to
Listen Your.IP.Address:Port Num

Tree
December 30th, 2005, 12:34
4.0.21

So you're using php_mysql, right?

Tree
December 30th, 2005, 13:02
Found a few other things that you should make sure of. If the lines in htpd.conf where the extensions are defined have a semicolon in front of them, TAKE IT OUT.

Also, if you're on an IIS server, set
cgi.force_redirect = 0.

Captain_Thunder
December 30th, 2005, 14:20
This is the page I'm testing my database connection with:

<?php
$username = "[myusernameishere";
$password = "[mypasswordishere]";
$hostname = "[myhostnameishere]";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
// you're going to do lots more here soon
mysql_close($dbh);
?>

When I was loading php_mysql.dll, it would say Unable to Connect to MySQL. Now, it just say nothing; blank page. What could this mean?

Tree
December 30th, 2005, 14:25
Mean's it's connected. Just to test, do this code:


if(mysql_connect($hostname, $username, $password))
{
echo "CONNECTED";
}
else
{
die("Can't connect because".mysql_error());
}

Captain_Thunder
December 31st, 2005, 08:25
Running that code, the page is still completely blank. I'm going to try a script that alters the database and then see if the changes are apparent.

Tree
December 31st, 2005, 10:27
Alright, that should work.