doubushi0031
2015-08-21 10:26 阅读 21
已采纳

在查询中带有“declare”的PDO Dblib返回false

Let's check this little piece of code:

$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));

This returns:

bool(false)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douxi8119 douxi8119 2016-04-09 13:16

    use 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));
    

    This returns:

    array(1) {
      [0]=>
      array(1) {
        ["tutu"]=>
        string(3) "100"
      }
    }
    
    点赞 8 评论 复制链接分享

相关推荐