Jump to content

Stored procedures


eddy556

Recommended Posts

Hi,  I'm trying to learn how to use stored procedures etc within a PHP script so I pulled up and old script and placed the SQL that it uses into a stored procedure within mysql.  This works perfectly (and varified using the mysql console) however returning the results to the original script is something different.

 

This was the original query string: $query  = "SELECT * FROM `playlist`";

 

Which has been replaced as (p1 is the stored procedure): $query = "call p1()";

 

I assumed everything else would fit it perfectly - the results from using both in the consol is identical.  However I am getting the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

Im pretty sure this is simple!

 

Many thanks  :D

 

Link to comment
https://forums.phpfreaks.com/topic/127837-stored-procedures/
Share on other sites

Just to follow up below is the whole of my code:

<?php


$link = mysql_connect('localhost', 'root', '*******');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

mysql_select_db("media_files");

//$query  = "SELECT * FROM `playlist`"; // <---The line which works using SQL
$query = "call p1();"; //<--The subsituted line

$result = mysql_query($query);


while($row = mysql_fetch_array($result)) //<--Error occurs here
{
    echo "FileName :{$row['filename']} <br>" .
         "Title : {$row['title']} <br>" .
         "Artist : {$row['artist']} <br>" .
	 "Length: {$row['length']}<br>";
} 

mysql_close($link);
?>

Link to comment
https://forums.phpfreaks.com/topic/127837-stored-procedures/#findComment-662006
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.