Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PDO从PHP调用存储过程到使用输入参数的MSSQL服务器_Php_Sql Server_Pdo_Fetch_Sqlsrv - Fatal编程技术网

使用PDO从PHP调用存储过程到使用输入参数的MSSQL服务器

使用PDO从PHP调用存储过程到使用输入参数的MSSQL服务器,php,sql-server,pdo,fetch,sqlsrv,Php,Sql Server,Pdo,Fetch,Sqlsrv,这不起作用: $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

这不起作用:

  $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=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_查询库将现有应用程序从IIS服务器移植到Linux服务器

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


救命啊!是我做错了什么,还是PDO不能打那种电话

出于某种原因,这是可行的:

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

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

我也许能接受这个。有人知道为什么其他方法不起作用吗?图书馆有什么不同吗

您收到了什么错误消息?根本没有错误消息。。这很奇怪。对不起,在我忘记您使用SQL Server之前。SQL Server在存储过程调用中不使用括号。