Results 1 to 12 of 12

Thread: [RESOLVED] calling store procedure

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] calling store procedure

    Hi guys how can I call the procedure using php ?

    Code:
    <?php 
    
    include 'config.php'; 
    include 'opendb.php'; 
    
    $qry = mysql_query("CALL HelloWorld()"); 
    $row = mysql_fetch_array($qry, MYSQL_NUM); 
    
    echo "$row[0]"; 
    
    include 'closedb.php'; 
    
    ?>

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: calling store procedure

    What's the problem?

    By the way, those quotes around $row[0] are superflous.

    Also you should consider using a proper data access library. PDO for PHP 5; MDB2 or mysqli for PHP 4.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: calling store procedure

    The problem is it does not print out my procedure. In the helloworld procedure, the select * from tablename. that's all i have. I just wanna test to see if I can call using php. But nothing is produced. I am using php5, and mysql 5 version too. Help?

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: calling store procedure

    Echo mysql_error() and see if there is any problem on the DB side. Run the query in something like phpMyAdmin and see if it returns anything.

  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: calling store procedure

    try this... same code, made some changes..

    PHP Code:
    <?php 

    include ('config.php'); 
    include (
    'opendb.php'); 

    $qry mysql_query(CALL HelloWorld()); 
    $row mysql_fetch_array($qryMYSQL_NUM); 

    echo 
    $row[0]; 

    include (
    'closedb.php'); 

    ?>
    Last edited by penagate; Apr 11th, 2007 at 11:26 PM. Reason: [highlight=php] => [php]
    My usual boring signature: Something

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: calling store procedure

    Sorry Dylan, I had to edit your post because the highlight tags made a mess of the [ character.

    Anyway, that won't work - CALL is a MySQL keyword and should be in the query text. As it is, that's a syntax error.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: calling store procedure

    The db is fine if I change that statement from CALL to select * from tablename. It's not working with CALL at all.

    Here is my procedure

    CREATE PROCEDURE HelloWorld()
    SELECT * from tablename;

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: calling store procedure

    What happens if you try my suggestions in post #4?

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: calling store procedure

    Hello, I put in that mysql_error("failed quering"). So I got failed querying on the page.

  10. #10
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: calling store procedure

    you don't put text inside of the parameter for mysql_error(), it's an optional parameter to identify what link you want to display the error for. you should probably look up the function on PHP.net if you have no idea how to use it, before plugging random things into it.

    PHP Code:
    <?php
      
    //like this:
      
    mysql_query($sql) or die(mysql_error());

      
    //or:
      
    mysql_query($sql);
      echo 
    mysql_error();
    ?>
    more information

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: calling store procedure

    This is what I got after I put mysql_error():

    PROCEDURE tablename.Helloworld can't return a result set in the given context

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: [RESOLVED] calling store procedure

    How is Helloworld defined, then?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width