php代码样例

<?phptry{$hostname="testserver.sqlserver.com";$port=1433;$dbname="dbname";$username="user";$pw="pwd";$dbh=newPDO("dblib:host=$hostname:$port;charset=UTF-8;dbname=$dbname","$username","$pw");}catch(PDOException$e){echo"Failed to get DB handle: ".$e->getMessage()."\n";exit;}$stmt=$dbh->prepare("select name from master..sysdatabases where name = db_name()");$stmt->execute();while($row=$stmt->fetch()){print_r($row);}unset($dbh);unset($stmt);?>