0
我想在我的PHP代碼中執行存儲過程,此存儲過程具有IN和OUT參數。存儲過程是這樣的:在PHP中使用IN和OUT參數執行存儲過程
USE [phl_pmx]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[PMX_SP_RecreateSynonymsOfSourceDb]
@sourceDb = phl
SELECT 'Return Value' = @return_value
GO
而且我已經寫了下面的代碼,但它一直給他不能執行,或者他只是不會呈東西的錯誤。
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
include_once 'DBC.php';
$link = mssql_connect('server', 'sa', 'password');
if (isset($_POST['StoredProcedure']))
{
mssql_select_db($id,$link);
$a = new TableOutput();
$a->getTables ("PMX_SP_RecreateSynonymsOfSourceDb","phl");
mssql_close($link);
}
elseif (isset($_POST['Value']))
{
$query =mssql_query("UPDATE [phl].[dbo].[PMX_EXDB] set ExtraDb='phl_pmx'");
mssql_close($link);
}
?>
這是它的功能。
<?php
class TableOutput {
function getTables($procname, $parameter) {
$stmt = null;
$data = null;
$vars = null;
$num = null;
$con = mssql_connect('server', 'sa', 'password');
if
(!$con) {
die('Could not connect: ' . mssql_error());
}
mssql_select_db("phl",$con);
$this->setStmt(mssql_init($procname, $con));
mssql_bind($this->getStmt(), '@sourceDb', $parameter, SQLINT2, false, false);
if ($rtn != 0) {
echo ("Errors happened when executing the stored procedure");
}
$exec = mssql_execute($this->getStmt());
$data = array();
$i = 0;
while ($row = mssql_fetch_assoc($exec)) {
$data[++$i] = $row;
}
unset($con);
unset($stmt);
return $data;
}
function setStmt($a_stmt) {
$this->stmt = $a_stmt;
}
function getStmt() {
return $this->stmt;
}
}
?>`
有誰知道如何正確的代碼,因爲它使我展示以下錯誤:
Warning: mssql_execute(): stored procedure execution failed in /var/www/mssql/management/DBC.php on line 24 Warning: mssql_fetch_assoc() expects parameter 1 to be resource, boolean given in /var/www/mssql/management/DBC.php on line 27
感謝您的評論,但它仍然無法正常工作 – Maikel 2011-05-18 07:09:26