note 97227 deleted from mysql.examples by danbrown

From: Date: Fri, 09 Apr 2010 13:11:41 +0000
Subject: note 97227 deleted from mysql.examples by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168077@lists.php.net to get a copy of this message
Note Submitter: sumitjoshi at themacrosoft dot com ---- Hi, friends. Here I am submitting the code for Stored Procedure. I was suffering and wondering for error solution for Stored Procedure. But now I found and enjoying with Stored Procedure. So submitting the code. The given code has three parts: 1. MySQL 2. MySQLi 3. PDO Here is code... <?php // MYSQL Version $mysql = mysql_connect('localhost', 'root', '',false,65536); mysql_select_db('dbcountry', $mysql); print "<h3>MYSQL: simple select</h3>"; $rs = mysql_query( "SELECT * FROM tblstate" ); while($row = mysql_fetch_assoc($rs)) { debug($row); } print "<h3>MYSQL: calling sp with out variables</h3>"; $rs = mysql_query( "CALL getCountry(1, @conname)" ); $rs = mysql_query( "SELECT @conname" ); while($row = mysql_fetch_assoc($rs)) { echo $row['@conname']; } print "<h3>MYSQL: calling sp with recordset</h3>"; $rs = mysql_query( "CALL getStateCountry(1)" ); while($row = mysql_fetch_assoc($rs)) { debug($row); } // MYSQLI Version $mysqli = new mysqli('localhost', 'root', '', 'dbcountry'); print "<h3>MYSQLI: simple select</h3>"; $rs = $mysqli->query( "SELECT * FROM tblstate;" ); while($row = $rs->fetch_object()) { debug($row)."<br>"; } print "<h3>MYSQLI: calling sp with out variables</h3>"; $rs = $mysqli->query( "CALL getCountry(1, @stateName)" ); $rs = $mysqli->query( "SELECT @stateName" ); while($row = $rs->fetch_object()) { debug($row); } print "<h3>MYSQLI: calling sp returning a recordset</h3>"; $rs = $mysqli->query( "CALL getState()" ); while($row = $rs->fetch_object()) { debug($row); } // PDO Version $pdo = new PDO("mysql:dbname=dbcountry;host=localhost", "root", ""); print "<h3>PDO: simple select</h3>"; foreach($pdo->query( "SELECT * FROM tblstate;" ) as $row) { debug($row); } print "<h3>PDO: calling sp with out variables</h3>"; $pdo->query( "CALL getCountry(1, @stateName)" ); foreach($pdo->query( "SELECT @stateName") as $row) { debug($row); } print "<h3>PDO: calling sp returning a recordset</h3>"; foreach($pdo->query( "CALL getState()" ) as $row) { debug($row); } function debug($o) { print "<pre>"; print_r($o); print "</pre>"; } ?>

« previous php.notes (#168077) next »