Jump to content

Mysql 'Commands out of sync; you can't run this command now'


SyncViews

Recommended Posts

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$$

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.