note 97227 added to mysql.examples

From: Date: Fri, 09 Apr 2010 06:02:43 +0000
Subject: note 97227 added to mysql.examples
Groups: php.notes 
Request: Send a blank email to php-notes+get-168058@lists.php.net to get a copy of this message
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>"; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 122.169.35.53 ---- Manual Page -- http://www.php.net/manual/en/mysql.examples.php Edit -- https://master.php.net/note/edit/97227 Del: integrated -- https://master.php.net/note/delete/97227/integrated Del: useless -- https://master.php.net/note/delete/97227/useless Del: bad code -- https://master.php.net/note/delete/97227/bad+code Del: spam -- https://master.php.net/note/delete/97227/spam Del: non-english -- https://master.php.net/note/delete/97227/non-english Del: in docs -- https://master.php.net/note/delete/97227/in+docs Del: other reasons-- https://master.php.net/note/delete/97227 Reject -- https://master.php.net/note/reject/97227 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168058) next »