我想连接到我的Ms sql server。网络服务器是Linux,但我的Localhost是Windows。现在我注释掉了我不需要的那个但是,PHP有没有办法检查它是否需要Windows的SQLSRV或Linux的MSSQL?
<!--
linux
-->
<?php
// $server = 'server';
//
// $link = mssql_connect($server, 'user', 'password');
//
// //select database
//
// mssql_select_db('DB');
// if (!$link) {
// die("Connection could not be established.<br>");
// }
?>
<!--
Windows
-->
<?php
$serverName = "server"; //serverName\instanceName
$connectionInfo = array( "Database"=>"DB", "UID"=>"user", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if(!$conn ) {
echo "Connection could not be established.<br>";
die( print_r( sqlsrv_errors(), true));
}
?>
答案 0 :(得分:0)
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
//use windows
} else {
//use mysql
}