MyBB Community Forums

Full Version: Procedure using $db->query or mysqli_multi_query
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi friends, I have a big problem with a Procedure, In phpmyadmin NOT SHOW ERROR, in phpmyadmin is doing the query perfectly
   $datos="CALL BUSCAR('%%',0,9900,'','DESC',0,0,0,'00')";
   $resultado = $db->query($datos);
   while ($filas = $db->fetch_array($resultado)) {
	$_SESSION['PRODS'][$filas['ID']]['PRODUCTO']=$filas['PRODUCTO'];
	$precioclient=round($filas['PRECIOCLIENT'],2);
	 eval('$listprods_c.= "'.$templates->get('TD_ajax_listprods_ciclo').'";');
   }
mysqli_next_result($resultado);
    $db->free_result($resultado); 

eval("\$page = \"".$templates->get("TD_AJAX")."\";");
output_page($page);

I am getting the following

Quote:MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
2014 - Commands out of sync; you can't run this command now
Query:
SELECT template FROM mybb_templates WHERE title='TD_ajax_listprods_ciclo' AND sid IN ('-2','-1','1') ORDER BY sid DESC LIMIT 1

What can i do?

Also tried with and with out this, and I still have the problem
        mysqli_next_result($resultado);
	$db->free_result($resultado);

Also tried with this, instead of use $db->query, but I still have the problem

$datos="CALL BUSCAR('%%',0,9900,'','DESC',0,0,0,'00')";
if (mysqli_multi_query($db->write_link, $datos)) {
    do {
        /* almacenar primer juego de resultados */
        if ($result = mysqli_store_result($db->write_link)) {
            while ($filas = mysqli_fetch_row($result)) {
				$_SESSION['PRODS'][$filas['ID']]['PRODUCTO']=$filas['PRODUCTO'];
				$precioclient=round($filas['PRECIOCLIENT'],2);
		     	eval('$listprods_c.= "'.$templates->get('TD_ajax_listprods_ciclo').'";');
            }
            mysqli_free_result($result);
        }
       
    } while (mysqli_next_result($db->write_link));
}

		$db->free_result($result);

eval("\$page = \"".$templates->get("TD_AJAX")."\";");
output_page($page);

What can I do?  Huh


Quote:MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
2014 - Commands out of sync; you can't run this command now
Query:
SELECT template FROM mybb_templates WHERE title='TD_ajax_listprods_ciclo' AND sid IN ('-2','-1','1') ORDER BY sid DESC LIMIT 1


Best Regards

I read than I should to use multi_query instead of query
myfile.php
<?php
    

define('IN_MYBB', 1);

//$templatelist="TD_Clasif,TD_clasif_colapsa,TD_clasif_sinjs";
require_once '../FORO/global.php';
$sql="CALL BUSCAR('%%',0,9900,'','DESC',0,0,0,'00');";
//$db->multi_query($sql);
if ($db->multi_query($sql))
{
  do
    {
    // Store first result set
    if ($result=$db->store_result($sql))
      {
      while ($filas=$db->fetch_array($result))
        {
        $html.=$filas['PRODUCTO'];
        }
      $db->free_result();
      }
    }
  while ($db->next_result());
}

eval("\$page = \"".$templates->get("TD_AJAX")."\";");
output_page($page);  
?>

db_mysqli.php I added thist

	function next_result(){
		@mysqli_next_result($this->current_link);
	}

	function store_result($sql){
		@mysqli_store_result($this->current_link,$sql);	
	}
	function multi_query($sql){
		@mysqli_multi_query($this->current_link,$sql);
	}

But I have still the error

Quote:SQL Error:
2014 - Commands out of sync; you can't run this command now
Query:
SELECT template FROM mybb_templates WHERE title='TD_AJAX' AND sid IN ('-2','-1','1') ORDER BY sid DESC LIMIT 1