Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known

sang picture sang · Jul 8, 2015 · Viewed 54.4k times · Source

I'm trying to connect to a localhost database using php.

but it's shown

Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp2\htdocs\wikifiesto\wf-insertcase.php on line 7

Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp2\htdocs\wikifiesto\wf-insertcase.php on line 7 error connecting to database

the structure of server, user, pass is localhost, pma, ' '

here's my code with the name 'wf-insertcase.php':

<?php
define('dbuser', 'pma');
define('dbpass', '');
define('dbserver', 'localhost');
define('dbname', 'wikifiesto');

$conn = mysql_connect(dbuser, dbpass, dbserver, dbname);

if (!$conn) {
    die('error connecting to database');
}

echo 'you have created case';
?>

Answer

pavel picture pavel · Jul 8, 2015

You have bad params order in your function. DB server has to be the first param.

$conn = mysql_connect(dbserver, dbuser, dbpass);

DB name isn't allowed there, use mysql_select_db(dbname).

All mysql_* are deprecated, see http://php.net/manual/en/function.mysql-connect.php and MySQLi extension.

$conn = mysqli_connect(dbserver, dbuser, dbpass, dbname);
             ^