本文实例讲述了php基于PDO连接MSSQL的方法。分享给大家供大家参考,具体如下:
<?php try { $hostname='117.79.93.222'; $port=1433;//端口 $dbname="csdn";//库名 $username="csdn_admin";//用户 $pw="123456";//密码 $dbh= new PDO("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw"); } catch (PDOException $e) { echo"Failed to get DB handle: ".$e->getMessage() ."n"; exit; } echo'connent MSSQL succeed'; $stmt=$dbh->prepare("SELECT * FROM CSDNUser"); $stmt->execute(); while ($row=$stmt->fetch()) { print_r($row); } unset($dbh); unset($stmt);
希望本文所述对大家PHP程序设计有所帮助。