Connecting to mysql via localhost
Hello all,
I am trying to learn about mysql. I am following O'Reilly's Learning MySQL book, and I've been working with some sample databases through the mysql monitor. All is well on that front.
I've now reached a chapter where I need to use php to connect to the database and run a query on it. The sample php file supplied does not work for me. I've tried putting some echo terms in the php file so I can see what's going on, and basically it looks like the php file execution hangs when a mysql connection attempt is made. No error is reported.
I've searched around, but since I do not understand why the failure occurs it's a bit hard for me to concentrate my search parameters to get to the bottom of it. So, to start from the basics, I've tried to use the following program:
<?php
echo "Connecting\n";
$mysqli = new mysqli("localhost", "root", "MYPASSWORD", "music");
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
else
{
echo "connection OK";
}
echo $mysqli->host_info . "\n";
$mysqli = new mysqli("127.0.0.1", "user", "password", "database", 3306);
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
?>
Unfortunately I get the same result. The first echo statement is executed, but then I see no further responses. It seems as if the mysql connection is the problem, but no useful errors are reported.
Any ideas where I can start to troubleshoot this?