views:

78

answers:

2

Whenever I try to create a mysqli object, as in;

$mysqli = new mysqli(host, user, pass, database);

...the page just loads for around a minute, then stops, showing all the content of the page up until that line.

info() says that MySQLi (and MySQL if that matters) are enabled, and I can access the MySQL CLI. I'm also working on a local machine, not a remote server.

I feel like I've missed something obvious. Can anyone shed some light on it?

Edit: just for clarification, I am actually putting real values into the mysqli constructor :)

+3  A: 

The fourth parameter to the constructor should be the database, not the table.

$mysqli = new mysqli($host, $user, $pass, $database);

You might also want to try displaying the error message:

if (mysqli_connect_errno()) {
   die("MySQL Connect Error: " . mysqli_connect_error());
} 

A possible problem is if MySQL is not using the default port. You can add the port number as an optional parameter in the mysqli constructor.

Mark Byers
Sorry, I meant database name. I have tried putting the error message code in, but nothing happens.
Dt7
I tried adding the port number, no success.
Dt7
@Dt7: What string are you using as the hostname?
Mark Byers
localhost....If it's worth mentioning, the code worked perfectly on my last install. I just recently replaced my hard drive and re-installed everything, but now it's just not working.
Dt7
@Dt7: Can you try running `netstat -a` from the command line and see if there is a connection in `LISTENING` state for `TCP 127.0.0.1:3306`?
Mark Byers
I've fixed it, thanks for triggering my memory!
Dt7
+2  A: 

Had to change the Windows hosts file (un-commented the localhost line).

Dt7