3

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?

2
  • What error messages do you get? Commented Jan 30, 2014 at 20:14
  • No error messages at all.. thats the weird thing. Commented Jan 30, 2014 at 20:42

1 Answer 1

9

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, before I missed the fact that that you were using SQL Server. SQL Server doesn't use parentheses for stored procedure calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.