note 115353 added to function.sqlsrv-prepare

From: Date: Thu, 10 Jul 2014 10:07:45 +0000
Subject: note 115353 added to function.sqlsrv-prepare
Groups: php.notes 
Request: Send a blank email to php-notes+get-199907@lists.php.net to get a copy of this message
Example of how to formally specify the params, AND get output. <?php // Setup connection $serverName = "serverName\sqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false) { die( print_r( sqlsrv_errors(), true)); } // specify params - MUST be a variable that can be passed by reference! $myparams['Item_ID'] = intval(-2); $myparams['Item_Name'] = "Foo"; // Set up the proc params array - be sure to pass the param by reference $procedure_params = array( array(&$myparams['Item_ID'], SQLSRV_PARAM_OUT), array(&$myparams['Item_Name'], SQLSRV_PARAM_OUT) ); // EXEC the procedure, {call stp_Create_Item (@Item_ID = ?, @Item_Name = ?)} seems to fail with various errors in my experiments $sql = "EXEC stp_Create_Item @Item_ID = ?, @Item_Name = ?"; $stmt = sqlsrv_prepare($conn, $sql, $procedure_params); if( !$stmt ) { die( print_r( sqlsrv_errors(), true)); } if(sqlsrv_execute($stmt)){ while($res = sqlsrv_next_result($stmt)){ // make sure all result sets are stepped through, since the output params may not be set until this happens } // Output params are now set, print_r($params); print_r($myparams); }else{ die( print_r( sqlsrv_errors(), true)); } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 80.194.194.98 ---- Manual Page -- http://php.net/manual/en/function.sqlsrv-prepare.php Edit -- https://master.php.net/note/edit/115353 Del: integrated -- https://master.php.net/note/delete/115353/integrated Del: useless -- https://master.php.net/note/delete/115353/useless Del: bad code -- https://master.php.net/note/delete/115353/bad+code Del: spam -- https://master.php.net/note/delete/115353/spam Del: non-english -- https://master.php.net/note/delete/115353/non-english Del: in docs -- https://master.php.net/note/delete/115353/in+docs Del: other reasons-- https://master.php.net/note/delete/115353 Reject -- https://master.php.net/note/reject/115353 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199907) next »