让我们检查一下这段代码:

$p = new PDO('dblib:host=HOST;dbname=DBNAME',USER,PASS);
$sql = "
declare @tutu int = 100;
select @tutu [tutu];
";
$stmt = $p->prepare($sql);
$stmt->execute();
var_dump($stmt->fetch(PDO::FETCH_ASSOC));

这将返回:
布尔(假)

最佳答案

使用nextRowset();

$p = new PDO('dblib:host=HOST;dbname=DBNAME',USER,PASS);
$sql = "
declare @tutu int = 100;
select @tutu [tutu];
";
$stmt = $p->prepare($sql);
$stmt->execute();
$stmt->nextRowset();
var_dump($stmt->fetch(PDO::FETCH_ASSOC));

这将返回:
array(1) {
  [0]=>
  array(1) {
    ["tutu"]=>
    string(3) "100"
  }
}

关于php - 在查询中带有“declare”的PDO Dblib返回false,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32138031/

10-08 22:48