Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/davidrooney/Sites/conn_test.php on line 10
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/davidrooney/Sites/conn_test.php on line 10
connection successful
Warning: mysqli::query(): Couldn't fetch mysqli in /Users/davidrooney/Sites/conn_test.php on line 14
hello world
Warning: mysqli::close(): Couldn't fetch mysqli in /Users/davidrooney/Sites/conn_test.php on line 18
The following is my conn_test.php file:
<?php
define('DB_NAME','testdb');
define('DB_USER','root');
define('DB_PASSWORD','password');
define('DB_HOST','localhost');
//Connecting to sql db
$connect = new mysqli('DB_HOST','DB_USER','DB_PASSWORD','DB_NAME');
if (!$connect) { die ('could not connect'); }
echo 'connection successful';
$message = $connect->query("SELECT first_name FROM testtable");
echo "$message <br/>";
echo "hello world";
$connect->close();
?>
The PHP code listed is able to connect to my SQL database "testdb" but making a query on the table "testtable" throws errors.
I have a column in that table 'first_name' with one entry as 'john'. I have verified my apache server is running fine with PHP7.1 enabled because I can output phpinfo() in a separate script. And MySQL server (mysql5.7) is also running and healthy because I can access it through Sequel Pro and create databases, tables, etc.
I can also manually query from Sequel Pro and 'john' is returned, so I know that query works as well.
I just started working with PHP but after everything I've read on the web, this code looks to be correct.
What am I missing?