I'm new to php and mysqli and trying to connect to database but I got this error
"Could not connect to mysqli:php_network_getaddresses: getaddrinfo failed: Name or service not known"
stick in ubuntu and use xampp this my code
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_NAME', 'first_db');
$dbc = mysqli_connect(DB_HOST,DB_USER,DB_NAME) OR die('Could not connect to mysqli:');
?>
Yes, your missing the password and since the error was php_network_getaddresses try to replace localhost with 127.0.0.1
<?php
define('DB_HOST', '127.0.0.1');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'first_db');
$dbc = mysqli_connect(DB_HOST,DB_USER, DB_PASS, DB_NAME) OR die('Could not connect to mysqli:');
?>
If you want to use secured connection you can use PDO:
$pdo= new PDO("mysql:host=127.0.0.1;dbname=first_db", 'root', 'password');
What mean php_network_getaddresses ?
It means PHP is trying to detect a hostname/address of a REMOTE PC (eg. a user browsing your page) but it cannot resolve the address (usually means that your server cannot query a DNS server or perform a lookup.)
If this is annoying you, you can surpess the error message by adding a '@' at the start of the method... like so..
by ballen