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/

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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. So, I did find a way to connect through ODBC, but I am not going down that road. I will just run CleanDB.
Sure, besides ODBC driver if you still wanna use SQL Azure, FreeTDS is an alternative: freetds.org/docs.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.