eddy556 Posted October 10, 2008 Share Posted October 10, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/127837-stored-procedures/ Share on other sites More sharing options...
eddy556 Posted October 10, 2008 Author Share Posted October 10, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/127837-stored-procedures/#findComment-662006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.