本文主要向大家介绍了SQLServer数据库之linux连sql server 2012 和开启PHP sqlserver扩展,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
连接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-msdblibmake && 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/freetdsmake && make install
pdo_dblib/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-dblib=/usr/local/freetdsmake && make install
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/pdo_dblib.soextension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/mssql.so
重启后测试testsqldb.phpmssql方式
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方式
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);
?>
本文由职坐标整理并发布,希望对同学们学习SQL Server有所帮助,更多内容请关注职坐标数据库SQL Server数据库频道!