Re: MySQL SP and execute using PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear Mahi,
You can do it using PDO extension of PHP. Alternatively you can use MySQLi extension. I am giving you a sample code using PDO extension:

Here it is:

<?php/* Execute a prepared statement by passing an array of values */
$sql = 'SELECT name, colour, calories
    FROM fruit
    WHERE calories < :calories AND colour = :colour';
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute(array(':calories' => 150, ':colour' => 'red'));
$red = $sth->fetchAll();
$sth->execute(array('calories' => 175, 'colour' => 'yellow'));
$yellow = $sth->fetchAll();
?> 
Example #2 Prepare an SQL statement with question mark parameters 
<?php
/* Execute a prepared statement by passing an array of values */
$sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < ? AND colour = ?');
$sth->execute(array(150, 'red'));
$red = $sth->fetchAll();
$sth->execute(array(175, 'yellow'));
$yellow = $sth->fetchAll();
?> 

 ====================================================
Nurul Ferdous
Programmer: BIPL
My Blog: http://www.ferdous.wordpress.com/
My LinkedIn: http://www.linkedin.com/in/nurulferdous
====================================================




________________________________
From: mahipal adi <mahi_vae2004@xxxxxxxxxxx>
To: php-objects@xxxxxxxxxxxxxxx
Sent: Friday, February 6, 2009 2:57:53 AM
Subject:  MySQL SP and execute using PHP


Hi 

Anybody can help me on MySql Stored Procedures.

I want to write a SP in MySql5 which will return multiple rows.
For Example: select * from users;

Please help me how to write SP in MySQL and call that SP using PHP.

Thanks & Regards

Mahi

Connect with friends all over the world. Get Yahoo! India Messenger at http://in.messenger .yahoo.com/ ?wm=n/

[Non-text portions of this message have been removed]


   


      

[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux