我正在尝试为我的 Apache 服务器启动并运行PDO,以便在它与我的 MS SQL 数据库交互时使用准备好的语句。似乎该库已安装并且连接正常,但我无法让它从表中返回任何信息
$dbh = new PDO ("dblib:host=$hostname;dbname=$database","$username","$password");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
$stmt = $dbh->prepare("SELECT * FROM asdf");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
print_r($result); //prints nothing
var_dump($stmt->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP)); //prints nothing
返回
**array(0) { }**
然而这
$dbh = new PDO("dblib:host=$hostname;dbname=$database", "$username", "$password");
} catch (PDOException $e) {
echo "Failed to get DB handle: ".$e - > getMessage()."\n";
}
$stmt = $dbh - > prepare("SELECT @@VERSION");
$stmt - > execute();
while ($row = $stmt - > fetch()) {
print_r($row);
}
unset($dbh);
unset($stmt);
打印出计算机详细信息。
Array ( [] => Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64) Apr 22 2011 19:23:43 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor) [0] => Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64) Apr 22 2011 19:23:43 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor) )
所以我认为 PDO 在某种程度上正在发挥作用。我只是有一些不好的语法吗?