连接sql server 2012数据库
http://www.freetds.org/userguide/choosingtdsprotocol.htm
下载安装 ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.20.tar.gz
./configure --prefix=/usr/local/freetds --with-tdsver=7.4 --enable-msdblib
make && make install
验证版本 /usr/local/freetds/bin/tsql -C
连接sql server 2012数据库
/usr/local/freetds/bin/tsql -H 192.168.1.200 -p 1433 -U username -P password
安装拓展
mssql
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-mssql=/usr/local/freetds
make && make install
pdo_dblib
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-dblib=/usr/local/freetds
make && make install
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/pdo_dblib.so
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/mssql.so
重启后测试testsqldb.php
mssql方式
<?php
header("Content-type: text/html; charset=utf-8");
//$msdb=mssql_connect("数据库IP","用户名","密码");
$msdb=mssql_connect("192.168.1.200:1433","username","password");
if (!$msdb) {
echo "connect sqlserver error";
exit;
}
mssql_select_db("SCCMdata",$msdb);
$result = mssql_query("select * from Agents", $msdb);
while($row = mssql_fetch_array($result)) {
print_r($row);
}
mssql_free_result($result);
?>
pdo_dblib方式
<?php
header("Content-type: text/html; charset=utf-8");
try {
$hostname = "192.168.1.200";
$port = 1433;
$dbname = "SCCMdata";
$username = "username";
$pw = "password";
$dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
$stmt = $dbh->prepare("select * from Agents");
$stmt->execute();
while ($row = $stmt->fetch()) {
print_r($row);
}
unset($dbh); unset($stmt);
?>
原文地址:http://blog.51cto.com/czwanga/2089211