PHP ~ connect to Microsoft SQL Server ~ MsSQL

Download the file ntwdblib.dll

file version: 2000.80.194.0

put it into the php folder and apache folder and Windows\System32\

for example of mine~~~put it into

D:\wamp\bin\php\php5.2.5\ntwdblib.dll
D:\wamp\bin\apache\apache2.2.8\bin\ntwdblib.dll
C:\Windows\System32\\ntwdblib.dll

restart sql server~apache~php

then it works~


PHP Code
======================================================================

$myServer = "BITTY-NOTEBOOK\SQLEXPRESS";
$myUser = "sa";
$myPass = "1234567890";
$myDB = "Gold";

$link = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
if (!$link || !mssql_select_db($myDB, $link)) {
    die('Unable to connect or select database!');
}

$sql = "SELECT [ID],[Buy],[Sell],[Time] FROM [Gold].[dbo].[Prices]";
$r =  mssql_query($sql, $link);
while($x = mssql_fetch_array($r))
{
    print $x['Buy'];
}
mssql_close($link);
======================================================================

http://www.9enjoy.com/post/236/

沒有留言: