0

I have a Linux server running Wordpress 4.2 and I have 2 Azure DB, one is SQL Server and the other is CleanDB.

The Windows Server(s)

  • Windows 7 Pro/Windows Server 2012 R2 sp1
  • Visual Studio 2013
  • SQL Server 2012 sp1
  • PHP 5.4 WP 4.2

Linux Server

  • CentOS 6.0
  • WP 4.2
  • PHP 5.4.31

It runs on SQL server, visual studio, and my php script on my Windows server to the CleanDB and SQL Server run fine and when I run the connection string on the Linux server to the CleanDB.

It won't connect when I run the Linux server to the SQL server.

I only allowed the DB to allow 4 calls and it isn't pulling. The IP ranges were added on the firewall.

I used the exact same string in all instances.

I found a few other related questions that some help:

SO References:

Cannot connect to azure db via SqlConnection

"Call to undefined function sqlsrv_connect()" when trying to connect to Azure DB from PHP

MSDN References:

https://azure.microsoft.com/en-us/documentation/articles/sql-database-php-how-to-use/

https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-connect-on-premises-sql-server/

Community
  • 1
  • 1
LJones
  • 35
  • 1
  • 8

1 Answers1

0

it won't connect when I run the Linux server to the SQL server.

Do you mean you couldn’t connect to SQL Azure from a Linux server while using sqlsrv drive? Please note, SqlSrv is a Windows driver, on Linux we can use PDO_DBLIB drive and PDO_ODBC (not recommend), more detailed info could be found at: http://php.net/manual/en/ref.pdo-dblib.php.

Code snippet via using PDO_DBLIB for your reference:

<?php
$dbHost = 'YourName.database.windows.net';
$dbUser = 'DBUserName';
$dbPass = 'DB Password';
$dbName = 'DB Name';
try {
    $pdo = new PDO("dblib:host=$dbHost:1433;dbname=$dbName", $dbUser, $dbPass); 
} catch (PDOException $e) {
    echo "Failed to get DB handle: " . $e->getMessage() . "\n";
    exit;
}

Code snippet via using PDO_ODBC for your reference:

$connection = odbc_connect("Driver={SQL Server};Server=$dbHost; Database=$dbName;", $dbUser, $dbPass);
    $qry = "SELECT * FROM Clienti";
    $result = odbc_exec($connection,$qry);
    // Get Data From Result
    while ($data[] = odbc_fetch_array($result));
        // Free Result
    odbc_free_result($result);
        // Close Connection
    odbc_close($conn);
        // Show data
    print_r($data);

AS to DB settings, please do not forget to manage allowed IP addresses on Azure portal, i.e. add your client IP address in Allowed IP Addresses section on Azure portal. https://msdn.microsoft.com/en-us/library/azure/ee621782.aspx#Troubleshooting

Feel free to let me know if I have any misunderstood on your issue.

Ming Xu - MSFT
  • 2,116
  • 1
  • 11
  • 13
  • Your answer was very helpful. Ultimately, I discovered that it cannot be done. With PHP 5.4+ from your link, it says that it can't be done. I looked into running a Windows server VM from a Linux server from [here](https://ask.sqlservercentral.com/questions/42618/is-there-any-way-to-get-ms-sql-to-work-on-linux-.html). So, I did find a way to connect through [ODBC](https://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx), but I am not going down that road. I will just run [CleanDB](https://azure.microsoft.com/en-us/documentation/articles/store-php-create-mysql-database/). – LJones Jul 07 '15 at 16:53
  • Sure, besides ODBC driver if you still wanna use SQL Azure, FreeTDS is an alternative: http://www.freetds.org/docs.html. – Ming Xu - MSFT Jul 08 '15 at 04:46