如何使用 PHP 和 SQL Server 2008 调用存储过程 [英] How to call stored procedure by using PHP and SQL Server 2008

查看:35
本文介绍了如何使用 PHP 和 SQL Server 2008 调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 SQL Server 2008 与 PHP 一起使用.我想在 PHP 中调用存储过程.

请指导我.

问候

解决方案

阅读 mssql_execute()

$conn = mssql_connect($host, $user, $pass);mssql_select_db('somedb', $conn);//调用一个简单的查询$result = mssql_query('SELECT * FROM sometable', $conn);//释放结果资源mssql_free_result($result);//然后执行程序$proc = mssql_init('some_proc', $conn);$proc_result = mssql_execute($proc);//等等...mssql_free_statement($proc);

编辑

阅读odbc_exec()

$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);$exec = odbc_exec($conn, "CALL storedProc()");

以及来自 php.net 文档的一个非常好的示例 odbc_execute():

<块引用>

示例

示例 #1 odbc_execute()odbc_prepare() 示例 在以下代码, $success 只会如果 myproc 的所有三个参数都为 TRUE是 IN 参数:

$a = 1;$b = 2;$c = 3;$stmt = odbc_prepare($conn, 'CALL myproc(?,?,?)');$success = odbc_execute($stmt, array($a, $b, $c));

<块引用>

如果你需要调用一个存储使用 INOUT 或 OUT 的程序参数,推荐的解决方法是为您使用本机扩展数据库(例如,mssql for MSSQL Server 或 oci8 for Oracle).

I am using SQL Server 2008 with PHP. I want to call a stored procedure in PHP.

Please guide me.

Regards

解决方案

read 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()

$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():

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:

$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).

这篇关于如何使用 PHP 和 SQL Server 2008 调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆