-1

The pdo connection to the sql server works fine, here is the code:

try {
    $host = "tcp:hdl324kjh.database.windows.net, 1433";
    $user = "user@hdl324kjh";
    $pwd = "password";
    $db = "my_db";
    $conn = new PDO ("sqlsrv:Server = $host; Database = $db", $user, $pwd);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = ("SELECT * FROM CUSTOMERS");
    $stmt = $conn->query("$sql");
    $row = $stmt->fetch();
    print_r($row);
    $conn = NULL;
} catch(Exception $e) {
    die(print_r($e));
}

But for some reason the mysql_connect doesn't seem to work:

$mysql_hostname = "hdl324kjh.database.windows.net:1433";
$mysql_user = "user@hdl324kjh";
$mysql_password = "password";
$mysql_database = "my_db";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");

mysql_select_db($mysql_database, $bd) or die("Could not select database");

$sql = mysql_query("SELECT * FROM CUSTOMERS");
while ($row = mysql_fetch_array($sql)) {
    echo $row['NAME'];
}

Here is the error message:

Connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known.

Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
user2672112
  • 199
  • 1
  • 14
  • Why would you want to create a mysql connection when you know how PDO works? – AgeDeO Sep 18 '15 at 07:48
  • The current website needs to be migrated onto a new server which is totally written for mysql_connect. So like to make it work for the same. :) – user2672112 Sep 18 '15 at 07:54
  • Please reconsider this: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – AgeDeO Sep 18 '15 at 08:14

2 Answers2

0

Come on, you cannot connect to ms sql server using mysql_connect in the first place.

While regarding this error, it is pretty clear - the system you are running your code on, knows nothing of the host hdl324kjh.database.windows.net

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

Your PDO code does not actually connect to a MySQL server, but a Microsoft SQL server. The two are very different things.

Evert
  • 93,428
  • 18
  • 118
  • 189