MySQL Stored Procedures not working with SELECT (basic question)

前端 未结 4 1634
野趣味
野趣味 2020-11-30 15:06

I am using a platform (perfectforms) that requires me to use stored procedures for most of my queries, and having never used stored procedures, I can\'t figure out what I\'m

相关标签:
4条回答
  • 2020-11-30 15:46

    Figured it out. This is not a bug with PHP (though it used to be) - it's a bug in some versions of phpmyadmin. The same bug intermittently reappears and is then fixed in various subversions (see above):

    #1312 - PROCEDURE [name] can't return a result set in the given context
    

    This behavior appears limited to SELECT statements within stored procedures inside phpmyadmin.

    Using a client like MySQL Workbench works around the problem (or you could upgrade phpmyadmin, but that's a pain if you're on a shared server like I am).

    Anyway, thanks to everyone for your help.

    0 讨论(0)
  • 2020-11-30 15:46

    When I execute the following:

    DELIMITER //
    DROP PROCEDURE IF EXISTS test_db.test_proc//
    CREATE PROCEDURE test_db.test_proc() SELECT 'foo'; //
    DELIMITER ;
    

    Followed by

    CALL test_db.test_proc();
    

    I shows me a result set like:

    +-----+
    | foo |
    +-----+
    | foo |
    +-----+
    

    I'm using PHP 5.3.1, MySQL 5.1.41 with phpMyAdmin 3.2.4.

    Perhaps you just misspelled your procedure name?
    Or could there be a problem with your PHP or MySQL installations? (Perhaps a bug. Have you tried updating to the latest versions?)

    0 讨论(0)
  • 2020-11-30 15:49

    This probably is centered around a bug dealing with PHP and SELECT within a stored procedure/routine. One possible work around is to use the SELECT... INTO inside of the stored procedure to bring the result down to one variable. This worked in some other cases that I read.

       SELECT * FROM category INTO c;
    
    0 讨论(0)
  • 2020-11-30 15:50

    Check your php version to see if this is a reported bug (see here).

    See this post: Can't return a result set in the given context

    0 讨论(0)
提交回复
热议问题