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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With