Kevin Kesicki Kevin Kesicki - 4 years ago 141
MySQL Question

Can't connect to phpMyAdmin database using mysqli

I am hosting a local database that I am having trouble connecting to. I have everything set up through MAMP. I know that my db user, pass, name, and host variables are correct, and I went into my Windows firewall to open up the TCP ports ingoing and outgoing. However, I am still getting the following message when I run the code below:

Connect failed: 2003

Does anyone know what this error number means? Below is the php code I am trying to run.

$db_user = 'db';
$db_pass = 'dbpass';
$db_name = 'dbname';
$db_host = 'localhost';

$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);

if ($mysqli->connect_errno)
printf("Connect failed: %s\n", $mysqli->connect_errno);

Answer Source

Try this

$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download