3

这不起作用:

  $dbh = new PDO("dblib:host=xxxx;dbname=xxx", "xxxxx", "xxxxx");

  $sth = $dbh->prepare("{exec wcweb_UserInfo(?)}");
  $sth->bindParam(1, $name);
  $sth->execute();

  while($result = $sth->fetch(PDO::FETCH_ASSOC)) {
    var_dump($result);
  }

这也不起作用:

  $dbh = new PDO("dblib:host=xxxxx;dbname=xxxx", "xxxxx", "xxxx");

  $sth = $dbh->prepare("{call wcweb_UserInfo(?)}");
  $sth->bindParam(1, $name);
  $sth->execute();

  while($result = $sth->fetch(PDO::FETCH_ASSOC)) {
    var_dump($result);
  }

这确实有效:

  $dbh = new PDO("dblib:host=xxxxx;dbname=xxxx", "xxxxx", "xxxx");

  $sth = $dbh->prepare("exec wcweb_UserInfo @userid=?");
  $sth->bindParam(1, $name);
  $sth->execute();

  while($result = $sth->fetch(PDO::FETCH_ASSOC)) {
    var_dump($result);
  }

我使用 2 尝试了上面的方法,它在有和没有大括号等的情况下都不起作用。我知道有些人会说,那么就按照它的工作方式来做吧?..问题是我正在使用 sqlsrv_query 库将现有应用程序从 IIS 服务器移植到 Linux 服务器。

应用程序中的所有数据库调用都写在使用此方法的函数中:{call wcweb_UserInfo(?)} .. 没有指定参数名称,因此我必须修改每个数据库调用以包含参数名称。我的印象是 PHP5 的 PDO 库可以执行相同类型的调用?

帮助!是我做错了什么,还是只是 PDO 无法进行此类调用?

4

1 回答 1

7

For some reason this works:

  $sth = $dbh->prepare("exec wcweb_UserInfo ?");
  $sth->bindParam(1, $name);
  $sth->execute();

  while($result = $sth->fetch(PDO::FETCH_ASSOC)) {
    var_dump($result);
  }

I might be able to live with this. Anyone know why the other methods do not work? Is it a difference in the libraries?

于 2014-01-30T20:33:36.980 回答