Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.