简体   繁体   中英

How to call stored procedure by using PHP and SQL Server 2008

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM