0

I have checked for something similar to my situation but have not found anything that fixes my problem. I have a database on my IIS web server called 'FracFocusRegistry' and am trying to connect to it using the following params.

$server = "scg-1441-6\FRACSQL";
$database = "FracFocusRegistry";
$user = "root";
$password = "";

$conn = new mysqli($server, $user, $password, $database);

if($conn->connect_errno > 0){
    die('Unable to connect to database [' . $conn->connect_error . ']');
}   

I am receiving the following error "Unable to connect to database [php_network_getaddresses: getaddrinfo failed: No such host is known. ]"

I have checked multiple times and the server name is in fact correct. I have found others with similar issues and opened firewall ports and changed settings in SQL manager and still nothing works. Any help would be greatly appreciated.

  • Maybe you should put address instead of name ? – frz3993 Jan 04 '16 at 17:22
  • 1
    Is your database server mysql or mssql. If it's the latter, are you trying to use mysqli to connect to mssql server? – frz3993 Jan 04 '16 at 17:28
  • @frz3993 it is mssql. I changed it to just the host like the post below and am getting a separate error now. – jeffrey verret Jan 04 '16 at 17:48
  • `mysqli` as the name implies, is for mysql server. You can use PHP PDO extension with drivers that can connect to mssql. You can refer to this question. (http://stackoverflow.com/questions/5953882/connecting-to-mssql-using-pdo-through-php-and-linux) – frz3993 Jan 04 '16 at 18:43

2 Answers2

0

For whatever reason it cannot determine what scg-1441-6\FRACSQL is. The host (of PHP, not the database) needs to be able to resolve this name to an address, so first check your hosts file. If the database is on the same machine you can try changing the name to localhost or even 127.0.0.1 (or the IP address of the machine with the database if it is on a different host) to see if that works.

HenryTK
  • 1,287
  • 8
  • 11
0

This is incorrect:

 $server = "scg-1441-6\FRACSQL";

mysqli expects ONLY the dns hostname/IP of the server. it is also not domain-aware, so a domain\host won't work at all. MySQL is literally looking for a hostname with s, c, ... \, F, etc... as the hostname.

Try

$server = "scg-1441-6";

only.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • ah ok thanks. So i used just the host name but now it is coming back with "Unable to connect to database [No connection could be made because the target machine actively refused it. ]" – jeffrey verret Jan 04 '16 at 17:40
  • something's blocking access to the mysql port, either mysql isn't on port 3306, or a firewall's blocking. – Marc B Jan 04 '16 at 17:41