MySQL Forums
Forum List  »  PHP

Connecting to mysql via localhost
Posted by: Brian Hoskins
Date: November 14, 2015 08:20AM

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?

Options: ReplyQuote


Subject
Written By
Posted
Connecting to mysql via localhost
November 14, 2015 08:20AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.