Connecting to a SQL Server 2012 database
Http://www.freetds.org/userguide/choosingtdsprotocol.htm
Download and install 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
Verifying version/usr/local/freetds/bin/tsql-c
Connecting to a SQL Server 2012 database
/usr/local/freetds/bin/tsql-h 192.168.1.200-p 1433-u username-p Password
Installation and expansion
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
Test testsqldb.php after reboot
MSSQL mode
<?phpheader("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 Way
<?phpheader("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);?>
Linux with SQL Server 2012 and the PHP server extension enabled