我使用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
答案 0 :(得分:2)
当您将debug设置为true时,ADODB使用其他函数来执行该语句。在这种情况下function _adodb_debug_execute(&$zthis, $sql, $inputarr)
如果debug设置为false,则ADODB使用function &_Execute($sql,$inputarr=false)
。当您检查两种方法的来源时,您可以清楚地看到差异。
<?php
function _adodb_debug_execute(&$zthis, $sql, $inputarr)
{
//ADODB prepares debug information dump...
$qID = $zthis->_query($sql,$inputarr);
//Here ADODB makes the difference
if ($zthis->databaseType == 'mssql') {
// ErrorNo is a slow function call in mssql, and not reliable in PHP 4.0.6
if($emsg = $zthis->ErrorMsg()) {
if ($err = $zthis->ErrorNo()) ADOConnection::outp($err.': '.$emsg);
}
} else if (!$qID) {
ADOConnection::outp($zthis->ErrorNo() .': '. $zthis->ErrorMsg());
}
if ($zthis->debug === 99) _adodb_backtrace(true,9999,2);
return $qID;
}
?>
这是_Execute函数
<?php
function &_Execute($sql,$inputarr=false){
//Here ADODB chooses which fn to use
if ($this->debug) {
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
$this->_queryID = _adodb_debug_execute($this, $sql,$inputarr);
} else {
$this->_queryID = @$this->_query($sql,$inputarr);
}
//...
if ($this->_queryID === false) { // error handling if query fails
//If debug ADODB prints backtrace regardless the result
if ($this->debug == 99) adodb_backtrace(true,5);
$fn = $this->raiseErrorFn;
if ($fn) {
$fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr,$this);
}
$false = false;
//Returns false no matter what...
return $false;
}
//...
}
?>
尝试将此添加到脚本中以测试脚本的行为,并记住如果执行失败,它将返回false
值。所以要注意返回的值。
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;
}
}
//add this line to free the resources after use.
mssql_free_result($rs);
return $rsArray;
} catch (ErrorException $e) {
echo $e->getMessage();
}
}
希望它有所帮助!!
答案 1 :(得分:0)
好的,在找到php.net评论后,即使我的freetds没有设置正确的名称,我也在使用ip地址。我也没有使用我使用7.0的V 8.0,一切都工作正常,直到这一点与商店程序。我尝试了在注释和DarkThrones中提供的mssql_free_result解决方案,但是没有用,但是当我使用adodb的close()方法时,它正在工作。它使用免费结果并传递查询ID。
如果有人可以评论为什么这是必要的,这将是伟大的。是因为我在使用大量内存还是其他东西?