[英]How to call stored procedure by using PHP and SQL Server 2008
I am using SQL Server 2008 with PHP. 我正在使用SQL Server 2008和PHP。 I want to call a stored procedure in PHP.
我想在PHP中调用存储过程。
Please guide me. 请指导我。
Regards 问候
read mssql_execute() 读取mssql_execute()
$conn = mssql_connect($host, $user, $pass);
mssql_select_db('somedb', $conn);
// Call a simple query
$result = mssql_query('SELECT * FROM sometable', $conn);
// Release the result resource
mssql_free_result($result);
// Then execute the procedure
$proc = mssql_init('some_proc', $conn);
$proc_result = mssql_execute($proc);
// Etc...
mssql_free_statement($proc);
EDIT 编辑
read odbc_exec() 读取odbc_exec()
$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
$exec = odbc_exec($conn, "CALL storedProc()");
and a very nice example from the php.net docs odbc_execute() : 和一个非常好的例子来自php.net docs odbc_execute() :
Examples
例子
Example #1 odbc_execute() and odbc_prepare() example In the following code, $success will only be TRUE if all three parameters to myproc are IN parameters:
示例#1 odbc_execute()和odbc_prepare()示例在以下代码中,如果myproc的所有三个参数都是IN参数,则$ success将仅为TRUE:
$a = 1;
$b = 2;
$c = 3;
$stmt = odbc_prepare($conn, 'CALL myproc(?,?,?)');
$success = odbc_execute($stmt, array($a, $b, $c));
If you need to call a stored procedure using INOUT or OUT parameters, the recommended workaround is to use a native extension for your database (for example, mssql for MS SQL Server, or oci8 for Oracle).
如果需要使用INOUT或OUT参数调用存储过程,建议的解决方法是使用数据库的本机扩展(例如,MS SQL Server为mssql,Oracle为oci8)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.