MSSQL的PHP​​驱动程序无法正常工作

I have a problem with the drivers that I've installed so my MSSQL could run side by side with PHP...

I have the following drivers placed in the directory file of PHP and also edited the .ini file of it:

  • php_sqlsrv_54_ts.dll
  • php_pdo_sqlsrv_54_ts.dll

I have the following error message:

  • PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.4.12/ext/php_sqlsrv_54_ts.dll' - %1 is not a valid Win32 application.

  • PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.4.12/ext/php_pdo_sqlsrv_54_ts.dll' - %1 is not a valid Win32 application.

And I have the following information about my PHP and MSSQL:

FOR PHP:

  • PHP Version 5.4.12
  • PHP installed via WAMP SERVER
  • Architecture x64
  • Thread safety enebled

FOR MSSQL:

  • MSSQL 2014 Express Edition
  • Am using Microsoft SQL Server Management Studio to manage Databases

Those are all the following information... Am I at messed here? please help me, Im still a newbie here in PHP especially in MSSQL.. CHEERS!


This is my code @JayBhatt what must be corrected to run the following code:

<?php
$myServer = "localhost";
$myUser = "sa";
$myPass = "joseph04";
$myDB = "cars";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");

//declare the SQL statement that will query the database
$query = "SELECT brand, model, year ";
$query .= "FROM cars ";
$query .= "WHERE brand='Honda'";

//execute the SQL query and return records
$result = mssql_query($query);

$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

//display the results
while($row = mssql_fetch_array($result))
{
  echo "<li>" . $row["brand"] . $row["model"] . $row["year"] . "</li>";
}
//close the connection
mssql_close($dbhandle);
?> 

I had the same problem and after a lot of research I had discovered that, Microsoft haven't released a 64 bit Version of driver for MSSQL.

The driver you have is for a 32 bit environment. And that's why it fails to load. Try switching to a 32 bit environment of WAMP server and it will work.

Hope this helps.

You can get unofficial x64 SQLSRV drivers for PHP . Try to install them. Here is your link. Just replace the dlls with the x64 dlls.

http://robsphp.blogspot.in/2012/06/unofficial-microsoft-sql-server-driver.html

Moreover you should be SQLSRV functions to connect to the database.
and MSSQL functions. Both of them use different drivers.
You should use "sqlsrv_connect" instead of "mssql_connect".

Refer: http://php.net/manual/en/book.sqlsrv.php