帮助我使用PHP ADODB,MSSQ执行带参数的存储过程。
$stmt = $db->PrepareSP('VM_SEARCH_SMSC');//stored procedure VM_SEARCH_SMSC
$search = 'test';
$string = 'SearchString';
$db->InParameter($stmt,$search,$string);
//return values.
$data = array();
$data['SNo'] = 0;
$data['SNSCID'] = 0;
$data['SMSCNAME'] = 0;
$data['MODE'] = '';
$data['ISACTIVE'] = 0;
$data['FIELD1'] = 0;
$data['ISBIND'] = 0;
$data['BNDOTHERRSRC'] = '';
$data['THRPT'] = '';
$db->OutParameter($statement, $data['SNo'], 'SNo');
$db->OutParameter($statement, $data['SNSCID'], 'SNSCID');
$db->OutParameter($statement, $data['SMSCNAME'], 'SMSCNAME');
$db->OutParameter($statement, $data['MODE'], 'MODE');
$db->OutParameter($statement, $data['ISACTIVE'], 'ISACTIVE');
$db->OutParameter($statement, $data['FIELD1'], 'FIELD1');
$db->OutParameter($statement, $data['ISBIND'], 'ISBIND');
$db->OutParameter($statement, $data['BNDOTHERRSRC'], 'BNDOTHERRSRC');
$db->OutParameter($statement, $data['THRPT'], 'THRPT');
$result = $db->Execute($stmt);
if (!$result){
print $db->ErrorMsg();
echo '<br /><br />';
}
错误:
SQLState:42000错误代码:201消息:[Microsoft] [SQL Server Native 客户端11.0] [SQL Server]过程或函数“VM_SEARCH_SMSC”期望 参数'@SearchString',未提供。
有人帮助我
答案 0 :(得分:0)
根据我的调查,似乎MSSQL的ADODB驱动程序不支持带参数的存储过程。使用sqlsrv。
$serverName = "XX.XX.XX.XXX";
$connectionInfo = array( "Database"=>"XXXXX", "UID"=>"XXXXX", "PWD"=>"XXX","ConnectionPooling" => "1","MultipleActiveResultSets"=>'0');
$conn = sqlsrv_connect( $serverName, $connectionInfo );
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$stmt = "{ CALL VM_SEARCH_SMSC (?)}"; //calling stored procedure with single parameter.
$search='t'; //search string
$params = array($search);
$result = sqlsrv_query( $conn, $stmt,$params,array('Scrollable' => 'buffered')); //add Scrollable to get sqlsrv_num_rows.
echo $row_count = sqlsrv_num_rows( $result );
echo '<br>';
if( $result === false) {
die( print_r( sqlsrv_errors(), true) );
} else{
while ($row = sqlsrv_fetch_array($result)) {
// This never prints.
echo "row:<br>"; var_dump($row); echo "<br><br>";
}
}
//print_r($row);
sqlsrv_free_stmt( $stmt);
这适用于sqlsrv。