問題描述
這不起作用:
$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?
這篇關于使用 PDO 從 PHP 調用存儲過程到使用 INPUT 參數的 MSSQL Server的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!