Jump to content

Stored Procedure error


raduenea

Recommended Posts

Hi

I create a stored procedure in mysql to show all the data from "biografie" table:

BEGIN
SELECT *  FROM biografie;
END 

 

In PHP a write the following code:

<?
$conexiune=mysql_connect($host,$user,$pass) or die ("conexiunea nu a fost stabilita");
mysql_select_db ($db,$conexiune) or die ("nu sa conectat la baza de date"); 

$q = mysql_query("CALL biografie()");
while($qw = mysql_fetch_assoc($q))
{
   echo $qw['id'].'<br>';
}

?> 

 

And it show the following error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/picturi/public_html/test.php on line 23

 

Can you please tell where it's the error ?

Link to comment
Share on other sites

I thing I got it.

 

To create the procedure:

DELIMITER //
CREATE PROCEDURE produse
     (
        IN   pid                    INT(11)       ,
        OUT p_titlu                      VARCHAR(15)   
     )
BEGIN
    SELECT titlu
    INTO   p_titlu
    FROM   produse
    WHERE  id = pid ;
END
//
DELIMITER ; 

 

To call and show:

CALL produse
   (
      1,
      @p_titel
   );

SELECT @p_titel       AS p_titel  

 

 

Link to comment
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.