使用 PDO 从 PHP 调用存储过程到使用 INPUT 参数的 MSSQL Server
这不起作用:
$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 服务器.
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.
应用程序中的所有数据库调用都是用使用此方法的函数编写的:{call wcweb_UserInfo(?)} .. 没有指定任何参数名称,因此我必须修改每个数据库调用以包含参数名称.我的印象是 PHP5 的 PDO 库可以执行相同类型的调用?
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?
帮助!是我做错了什么还是只是 PDO 无法进行这些类型的调用?
Help! Is there something I am doing wrong or is it just that PDO can't make those kinds of calls?
推荐答案
出于某种原因,这有效:
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?
相关文章