使用 PHP ADODB、MSSQL sqlsrv 执行带参数的存储过程
execute stored procedure with parameters using PHP ADODB, MSSQL sqlsrv
帮我用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 Error Code: 201 Message: [Microsoft][SQL Server Native
Client 11.0][SQL Server]Procedure or function 'VM_SEARCH_SMSC' expects
parameter '@SearchString', which was not supplied.
有人帮帮我
根据我的调查,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。
帮我用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 Error Code: 201 Message: [Microsoft][SQL Server Native Client 11.0][SQL Server]Procedure or function 'VM_SEARCH_SMSC' expects parameter '@SearchString', which was not supplied.
有人帮帮我
根据我的调查,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。