Calling stored procedure from PHP using PDO to MSSQL Server using INPUT Paramters

Deadly 提交于 2019-12-17 21:12:44

问题


This does not work:

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

This also does not work:

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

This DOES work:

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

I tried the above using 2 that did not work with and without the curly brackets, etc. I know some would say, well just do it the way it works? .. The problem is I am porting an exising application from an IIS Server using the sqlsrv_query library to a Linux server.

All of the database calls in the app are written in functions that use this method: {call wcweb_UserInfo(?)} .. None of the parameter names are specified, so I would have to modify every database call to include the parameter names. I was under the impression that the PDO library for PHP5 can do those same kind of calls?

Help! Is there something I am doing wrong or is it just that PDO can't make those kinds of calls?


回答1:


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?



来源:https://stackoverflow.com/questions/21466503/calling-stored-procedure-from-php-using-pdo-to-mssql-server-using-input-paramter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!