Error: Commands out of sync - HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Error: Commands out of sync - HELP!

Post by GeXus »

I receive the following error message "Error: Commands out of sync; you can't run this command nowQuery: CALL get_categories();" when using mysqli and stored procedures... Any idea why I would get this? The code is below... thanks a lot!! I'm dying here!

Code: Select all

<?
session_start();
error_reporting(E_ALL);
require_once('includes/config.php');
$db = mysql_connection();

        if(isset($_GET['cat_id'])){
       
                $cat_id = $_GET['cat_id'];

        }else{

                $cat_id = 1;
        }

if(isset($_GET['delete_cat_id'])){
       
        $delete_cat_id = $_GET['delete_cat_id'];
        if($query = $db->query("CALL delete_category_node($delete_cat_id);") === TRUE){

                        echo "Category Deleted";

        $query->close();
        }
}

        //GET CATEGORIES BY NODE
        $sql = "CALL get_category_nodes($cat_id);";
        $query = $db->query($sql);
        if ( !$query ) {
            echo '<div>Error: ', $db->error, '</br>Query: ', htmlentities($sql), "</div>\n";
                die();
        }       

        $row = $query->fetch_array(MYSQLI_ASSOC);

                while($row = $query->fetch_array(MYSQLI_ASSOC)){

                        echo "<a href=?cat_id=" . $row['category_id'] . ">" . $row['name'] . "</a> [ <a href=\"?delete_cat_id=" . $row['category_id'] . "\">x</a> ]<br/>";
        }
        $query->close();


        //GET ALL CATEGORIES
        $sql = "CALL get_categories();";
        $query = $db->query($sql);
                if ( !$query ) {
                echo '<div>Error: ', $db->error, '</br>Query: ', htmlentities($sql), "</div>\n";
                die();
                }
               
        $row = $query->fetch_array(MYSQLI_ASSOC);
                while($row = $query->fetch_array(MYSQLI_ASSOC)){
               
                        echo "<a href=?cat_id=" . $row['category_id'] . ">" . $row['name'] . "</a> [ <a href=\"?delete_cat_id=" . $row['category_id'] . "\">x</a> ]<br/>";
        }
        $query->close();




$db->close();
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

new thread, same problem, see viewtopic.php?p=375784
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Good catch volka.

Locked.
Locked