SyncViews Posted May 2, 2008 Share Posted May 2, 2008 This worked fine untill I made one of the sql statements into a prodcedure. Now I'm getting some error about commands being out of sync <?php ... $result = $sql->query("CALL forum_get_index()") or exit(__LINE__.':'.$sql->error); $i = -1; while($row = $result->fetch_assoc()) { //check if viewing is allowed. If viewing of a section is dissallowed but viewing of the contained forums is allowed the forum will appear in the section "above" if(!($user_admin || $row["visible"])) { //check all valid permissions forum_permission($row["forum_id"], $permissions); if(!$permissions["visible"]) continue; } unset($row["visible"]); if($row["depth"] == 0) { //increment counter and reduce amount of needed data $sections[++$i]["data"] = array( 'id' => $row["forum_id"], 'name' => $row["forum_name"], 'desc' => $row["forum_desc"] ); } else { $row["last_post_time"] = date("M j Y, h:i A",$row["last_post_time"]); unset($row["depth"]); $sections[$i]["forums"][] = $row; } } $result->close(); ... ?> <?php function forum_permission($forum, &$permissions) { global $sql, $user_id; //check user permissions $result = $sql->query("SELECT visible, create_topic, post_reply FROM permissions_forum_user WHERE user_id=$user_id AND forum_id=$forum") or exit(__LINE__.':'.$sql->error); //<---ERROR HERE<--- if($result->num_rows > 0) { $data = $result->fetch_assoc(); if($data["visible"]) $permissions["visible"] = true; if($data["create_topic"]) $permissions["create_topic"] = true; if($data["post_reply"]) $permissions["post_reply"] = true; } $result->close(); //check users groups $result = $sql->query(" SELECT p.visible, p.create_topic, p.post_reply FROM group_users u, permissions_forum_group p WHERE p.group_id = u.group_id AND u.user_id = $user_id ") or exit(__LINE__.':'.$sql->error); while($row = $result->fetch_assoc()) { if($row["visible"]) $permissions["visible"] = true; if($row["create_topic"]) $permissions["create_topic"] = true; if($row["post_reply"]) $permissions["post_reply"] = true; } $result->close(); } ?> The procedure DELIMITER $$ DROP PROCEDURE IF EXISTS forum_get_index$$ CREATE PROCEDURE forum_get_index() BEGIN SELECT node.forum_id, node.forum_name, node.forum_desc, node.topics, node.posts, node.last_topic_id, node.last_topic_name, node.last_post_id, node.last_post_time, node.last_user_id, node.last_user_name, node.visible, sub.depth FROM forums AS node, ( SELECT node.forum_id AS forum_id, COUNT( parent.forum_id ) -1 AS depth FROM forums AS node, forums AS parent WHERE node.left BETWEEN parent.left AND parent.right GROUP BY node.forum_id ORDER BY node.left ) AS sub WHERE node.forum_id = sub.forum_id GROUP BY node.forum_id HAVING sub.depth < 2 ORDER BY node.left; END$$ Link to comment https://forums.phpfreaks.com/topic/103890-mysql-commands-out-of-sync-you-cant-run-this-command-now/ Share on other sites More sharing options...
DyslexicDog Posted May 2, 2008 Share Posted May 2, 2008 is your sql object using mysql or mysqli? Link to comment https://forums.phpfreaks.com/topic/103890-mysql-commands-out-of-sync-you-cant-run-this-command-now/#findComment-531862 Share on other sites More sharing options...
SyncViews Posted May 2, 2008 Author Share Posted May 2, 2008 opps thought I included the connection in the first code snippet... mysqli Link to comment https://forums.phpfreaks.com/topic/103890-mysql-commands-out-of-sync-you-cant-run-this-command-now/#findComment-532121 Share on other sites More sharing options...
SyncViews Posted May 3, 2008 Author Share Posted May 3, 2008 So can anyone explain why I get that error because Ive really got no idea why it doesn't work with a stored procedure ? Link to comment https://forums.phpfreaks.com/topic/103890-mysql-commands-out-of-sync-you-cant-run-this-command-now/#findComment-532480 Share on other sites More sharing options...
DyslexicDog Posted May 4, 2008 Share Posted May 4, 2008 I found this article http://www.rooftopsolutions.nl/article/173. Not sure if that's your problem. *EDIT I read your code* You say you created a Stored procedure in your database. If that is related to the problem, I don't see where the stored procedure is called by your PHP. I maybe way off here but is there more going on with every page load? Link to comment https://forums.phpfreaks.com/topic/103890-mysql-commands-out-of-sync-you-cant-run-this-command-now/#findComment-532691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.