[英]Executing stored procedure with IN and OUT parameters in PHP
I want to execute a stored procedure into my PHP code, this stored procedure has an IN and an OUT parameter. 我想将存储过程执行到我的PHP代码中,该存储过程具有IN和OUT参数。 The stored procedure is this:
存储过程是这样的:
USE [phl_pmx]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[PMX_SP_RecreateSynonymsOfSourceDb]
@sourceDb = phl
SELECT 'Return Value' = @return_value
GO
And I already wrote the following code, but it keeps giving errors that he can't execute it, or he just won't show a thing. 而且我已经写了下面的代码,但是它不断出现错误,使他无法执行它,或者他只是不显示任何东西。
<?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);
}
?>
This is the function for it. 这就是它的功能。
<?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;
}
}
?>`
Does anyone know how to correct the code, because it keeps showing me the following error: 有谁知道如何更正代码,因为它不断向我显示以下错误:
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
I don't know MSSQL stored procedures, so I can't analyse your stored procedure. 我不知道MSSQL存储过程,因此无法分析您的存储过程。 If your proc is returning multiple resultsets you need to use mssql_next_result :
如果您的proc返回多个结果集,则需要使用mssql_next_result :
do {
while ($row = mssql_fetch_row($exec)) {
$data[++$i] = $row;
}
} while (mssql_next_result($exec));
Maybe this helps. 也许这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.