Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts

    Stored procedure not working when being called by php

    Hi all, the following works , but when I use CALL getAudio() I get no result.

    PHP Code:
    <?php

    $connection 
    mysql_connect('localhost''root''');
            
    mysql_select_db('mcomp'$connection) or die(mysql_error());

        
    //  $q = "CALL getAudio()";
          
           
    $q "SELECT * FROM tbaudio t;";
            
    $result mysql_query($q$connection);
            
            while ( 
    $row mysql_fetch_array $result ) ) {
                echo  
    $row ["id"];
            }

    ?>
    I have verified the sp getAudio() on the query browser

    any ideas?


  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    Try
    Code:
    SELECT getAudio();
    I think it should work ... I always call stored functions via SELECT. I did not call them without the FROM clause but since it is optional in MySQL, I think it should work.
    Last edited by SKDevelopment; 09-18-2009 at 12:46 AM.

  • #3
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    That doesn't work either


  • #4
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #5
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by hinch View Post

    Could you help me use that with the code I was trying, I am not sure what to do.


  • #6
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    I tried this

    PHP Code:
    <?php

    $connection 
    mysql_connect('localhost''root''');
            
    mysql_select_db('mcomp'$connection) or die(mysql_error());

        
          
    $stmt $connection->prepare("call getAudio()");
          
    $stmt->bindParam(1$resultPDO::PARAM_STR4000);
          
    $stmt->execute();

            while ( 
    $row mysql_fetch_array $result ) ) {
                echo  
    $row ["id"];
          }
        
    /*    $q = "SELECT * FROM tbaudio t;";
            $result = mysql_query($q, $connection);
        
             while ( $row = mysql_fetch_array ( $result ) ) {
                echo  $row ["id"];
            } */



    ?>
    but got this:


    Fatal error: Call to a member function prepare() on a non-object


  • #7
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    When it is necessary to work with the DB using PDO, mysql_connect() is not used. Please see how to connect to the database here.

  • #8
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    This PDO stuff looks complex



  •  

    Posting Permissions

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