PDA

View Full Version : Connecting to MySQL with PHP on Apache 2.2


sypher373
Mar 6, 2007, 08:43 AM
Hello all,

Just a little background on my system.

I am running Windows XP Pro SP2. Firewall is disabled.

Running Apache 2.2, PHP5 and MySQL server 5.1.

I am trying to simple interface with my MySQL database using a webpage running PHP. I have tried using the mysql_connect(host, name, password) function, checked all the parameters 50,000 times and I still cannot connect. As a test, I wrote a small script that resembled this:

<?php

Echo "start";
Mysql_connect($host, $name, $pass);
Echo "end";

?>

The problem with that is, only the "start" printed. I have no indication that I ever got connected to the database, as the insertion of a create db command yielded nothing. I have even tried the connection function using the 'or die("Error"); part. No error, no connection.

MY firewall is turned off, MySQL operates fine at the command line, and apache is working fine. All PHP commands work, I just can't seem to interface with MySQL.

Any suggestions? :confused: :confused:

I forgot to mention, this is all being run on the same machine, making my hostname localhost. I have tried localhost as well as 127.0.0.1

BenReilly
May 10, 2007, 11:25 PM
Try the following:
<?PHP
$db_server = 'localhost';
$db_name = 'whateveritis';
$db_user = 'root';
$db_passwort = 'password';

$db = @mysql_connect($db_server, $db_user, $db_passwort)
or die ('The Connection could not be established');

$db_check = @mysql_select_db($db_name);

if($db)
echo 'Connection to Database is established';
?>
If you are connected to the db you will receive the last message.

interinfinity
Jan 11, 2008, 04:48 PM
Make sure mysql services running in services.msc, try restarting apache and msql servies