7

I have used php5ts.dll files for php and ms sql server connection on my windows sytem but i need to do same for linux but same dll files do not work on linux as they are for windows. After Rnd I came to know that corresponding to dll files in windows we need .so files in linux SO question. I don't have knowledge that what excatly these .dll files do in php to connect it to ms sql server.

It would be great if some one help me understanding that why same does not work for linux and what could be the solution?

I also came through one same question here where user has asked similar question for windows instead of linux.

Following is the piece of code we use to create connection:

  • db.driver = "pdo_sqlsrv"
  • db.host = ""
  • db.dbname = ""
  • db.user = ""
  • db.password = ""

and driver files are placed here at D:\wamp\bin\php\php5.4.16 >>php5ts.dll and D:\wamp\bin\php\php5.4.16\ext >> php_sqlsrv_54_ts.dll

Community
  • 1
  • 1
Always_a_learner
  • 4,585
  • 13
  • 63
  • 112
  • 1
    Er No .dll files work on linux. Are you trying to copy a Windows Apache/PHP install to a linux system? – RiggsFolly Jan 08 '16 at 09:55
  • 1
    This may get you started http://pointbeing.net/weblog/2010/05/successful-microsoft-sql-server-support-for-php-on-linux.html – RiggsFolly Jan 08 '16 at 09:57
  • yes. I want to configure my project on linux. My project use ms sql server for database and php as server scripting language. – Always_a_learner Jan 08 '16 at 09:57
  • 1
    First question; how can you connect sql db in windows(code). Second question : Do you use different server for php and db driver for linux? – hurricane Jan 08 '16 at 10:02
  • I am using : db.driver = "pdo_sqlsrv" db.host = "" db.dbname = "" db.user = "" db.password = "" for php and ms sql server connection and php_sqlsrv_54_ts.dll for drivers. But same does not work when configured on linux. – Always_a_learner Jan 08 '16 at 10:21
  • 1
    ["The PDO_SQLSRV extension is only compatible with PHP running on Windows. For Linux, see ODBC and » Microsoft's SQL Server ODBC Driver for Linux."](http://php.net/manual/en/ref.pdo-sqlsrv.php). So it looks like you can't use your chosen driver for both platforms. I'm guessing you should probably use something like FreeTDS or PDO_ODBC, but I don't have any experience connecting to SQL Server from a unix PHP install. – Matt Gibson Jan 08 '16 at 11:07
  • Possible duplicate of [PHP 5.4 on Linux: How to connect with MS SQL Server 2008?](http://stackoverflow.com/questions/10834175/php-5-4-on-linux-how-to-connect-with-ms-sql-server-2008) – miken32 Jan 16 '17 at 22:43

1 Answers1

0

To connect from php5 on a linux machine to Micrsoft SQL is a little couter intuitive, you actually need to use the sybase extension and the pear MDB2 driver for MS SQL. The MSSQL functions in PHP5 actually alias the Sybase functions if you can't install the MSSQL extension due to OS limitations.

To solve this use the following commands...

sudo apt-get install php5-sybase
pear install --nodeps MDB2_Driver_mssql

After doing that you can test it using...

<?php

$server = 'servername';
$username = 'sa';
$password = 'password';
$database = 'xxx';
$connection = mssql_connect($server, $username, $password);

if($connection != FALSE)
{
echo "Connected to the database server OK<br />";
}
else
{
die("Couldn't connect");
}

if(mssql_select_db($database, $connection))
{
echo "Selected $database ok<br />";
}
else
{
die('Failed to select DB');
}

$query_result = mssql_query('SELECT @@VERSION');
$row = mssql_fetch_array($query_result);

if($row != FALSE)
{
echo "Version is {$row[0]}<br />";
}
mssql_free_result($query_result);
mssql_close($connection);
Chris Rutherfurd
  • 1,617
  • 1
  • 15
  • 32