MySQL Stored Procedure - How to process resultset in SP Help

  • httpftp21
  • Graduate
  • Graduate
  • httpftp21
  • Posts: 101

Post 3+ Months Ago

Hello All,

How To process a result in a stored procedure
Suppose i have
Code: [ Select ]
sql = "SELECT fname, lname FROM students WHERE name ='Sam' ";


How will i fetch this result in variable and loop in a SP like we do in PHP as:
Code: [ Select ]
$sql = "SELECT fname, lname FROM students WHERE name ='Sam' ";
$qSql = mysql_query($sql);
if ($qSql )
{
    $fArr = mysql_fetch_array($qSql);
    if ($fArr)
    {
        foreach ($fArr as $arrTmp)
        {
            $arrResult['fName'] = $arrTmp['fname'];
            $arrResult['lName'] = $arrTmp['lname'];
        }
    }
}
  1. $sql = "SELECT fname, lname FROM students WHERE name ='Sam' ";
  2. $qSql = mysql_query($sql);
  3. if ($qSql )
  4. {
  5.     $fArr = mysql_fetch_array($qSql);
  6.     if ($fArr)
  7.     {
  8.         foreach ($fArr as $arrTmp)
  9.         {
  10.             $arrResult['fName'] = $arrTmp['fname'];
  11.             $arrResult['lName'] = $arrTmp['lname'];
  12.         }
  13.     }
  14. }


How we can do such type of looping in SP ?
How can we split string in SP and loop as we do in PHP ?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

I don't mean to force you to do anything, but is there a reason you need to use a SProc? Stored Procedures are pretty horrid, I've done extensive work where we had an outdated site using a ton of sprocs. They cause way more problems than they solve.
  • httpftp21
  • Graduate
  • Graduate
  • httpftp21
  • Posts: 101

Post 3+ Months Ago

Any help

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 145 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.