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

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

I beg you, please.

Hello

+4
source share
1 answer

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 good example from php.net odbc_execute () docs:

<strong> Examples

Example # 1 odbc_execute () and odbc_prepare () Example. the following code, $ success will only be TRUE if all three parameters for 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 the 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).

+8
source

All Articles