ADODB / SQL Server mssql_execute 存储过程失败,但如果 debug 设置为 true 则可以工作
我正在使用 ADODB 从 PHP 连接到 SQL Server 数据库。我有几个执行得很好的存储过程。由于某种原因我创建的最后一个调用一直失败。我把 debug 设置为 true 并且它工作得很好。我不知道为什么会发生这种情况。
这是我得到的错误
Error: mssql_execute() [<a href='function.mssql-execute'>function.mssql-execute</a>]: stored procedure execution failed in /path/to/adodb/lib/adodb5/drivers/adodb-mssql.inc.php on line 768
这是我创建的用于将所有存储过程传递给的方法,就像我说的那样,它与其他存储过程一起工作得很好,但是这个方法和我已经仔细检查了参数和存储过程的所有拼写是否正确。
protected function _getSpArray($db, $sp, array $spParams) {
try {
$stmt = $db->PrepareSP($sp);
foreach ($spParams as $param) {
$db->InParameter($stmt, $param[0], $param[1]);
}
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$rs = $db->Execute($stmt);
$rsArray = array();
if (!$rs) {
echo 'No records found \n';
return;
}
else {
foreach ($rs as $k => $row) {
$rsArray[$k] = $row;
}
}
return $rsArray;
} catch (ErrorException $e) {
echo $e->getMessage();
}
}
它在 adodb5/drivers/adodb-mssql.inc.php 的 #768 行上失败
$rez = mssql_execute($sql[1]);
,并且 sql 数组具有这些值
[0] stored_procedure_name
[1] resource id='657' type='mssql statement'
我在 PHP.net 上看到了以下评论,我将我的 freetds 主机名更改为与IP 地址仍然没有。我不确定免费结果,因为我使用的是 adodb。
http://www.php.net/manual/en/function .mssql-execute.php#93938
我使用的是 adodb 5.11
I am connecting to a SQL Server database from PHP using ADODB. I have several stored procedures that I have been executing just fine. The last call that I have created for some reason keeps failing. I put debug as true and it works just fine. I have no idea why this would be happening.
here is the error I get
Error: mssql_execute() [<a href='function.mssql-execute'>function.mssql-execute</a>]: stored procedure execution failed in /path/to/adodb/lib/adodb5/drivers/adodb-mssql.inc.php on line 768
Here is the method I created to pass all my stored procedures to, like I said it works fine with other stored procedures but this one and I have double checked that all the spellings of the parameters and stored procedure are correct.
protected function _getSpArray($db, $sp, array $spParams) {
try {
$stmt = $db->PrepareSP($sp);
foreach ($spParams as $param) {
$db->InParameter($stmt, $param[0], $param[1]);
}
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$rs = $db->Execute($stmt);
$rsArray = array();
if (!$rs) {
echo 'No records found \n';
return;
}
else {
foreach ($rs as $k => $row) {
$rsArray[$k] = $row;
}
}
return $rsArray;
} catch (ErrorException $e) {
echo $e->getMessage();
}
}
It is failing on this line #768 of adodb5/drivers/adodb-mssql.inc.php
$rez = mssql_execute($sql[1]);
and the sql array has these values
[0] stored_procedure_name
[1] resource id='657' type='mssql statement'
I have seen the following comments on PHP.net, I changed my freetds host name to be something different then the IP address and still nothing. I am not sure about the free result since I am using adodb.
http://www.php.net/manual/en/function.mssql-execute.php#93938
I am using adodb 5.11
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您将 debug 设置为 true 时,ADODB 使用其他函数来执行该语句。在本例中
function _adodb_debug_execute(&$zthis, $sql, $inputarr)
如果 debug 设置为 false,ADODB 使用
function &_Execute($sql,$inputarr=false)
代码>.当您检查这两种方法的来源时,您可以清楚地看到差异。这是 _Execute 函数。
尝试将其添加到脚本中以测试脚本的行为,并记住,如果执行失败,它将返回
false
值。所以要注意返回值。希望有帮助!!
When you set debug as true ADODB uses other function to execute the statement. In this case
function _adodb_debug_execute(&$zthis, $sql, $inputarr)
If debug is set to false ADODB uses
function &_Execute($sql,$inputarr=false)
. When you check the source for both methods you can clearly see the difference.Here is the _Execute function
Try adding this to your script to test the behaviour of the script and keep in mind that if the execute fails it will return a
false
value. So take care with the returned value.Hope it helps!!
好的,在找到 php.net 注释后,尽管我的 freetds 没有设置正确的名称,但我使用的是 IP 地址。我也没有使用 V 8.0,而是使用 7.0,直到此时,商店程序一切都工作正常。我尝试了评论和 DarkThrones 答案中提供的 mssql_free_result 解决方案,但这不起作用,但是当我使用 adodb 的 close() 方法时,它正在工作。它使用免费结果并传递查询 ID。
如果有人可以评论为什么这是必要的,那就太好了。是因为我用了太多内存还是什么?
Ok, after finding the php.net comments, even though my freetds wasn't setup with the proper name, I was using the ip address. I also wasn't using the V 8.0 I was using 7.0 and everything was working fine up until this point with the store procedures. I tried the mssql_free_result solution provide in the comments and DarkThrones answer and that didn't work but when I used adodb's close() method it is working. It uses free result and passes a query id.
If someone can comment as to why this is necessary that would be great. Is it because I was using up to much memory or something?