PHP - Commands out of sync; you can"t run this command now

 
Vista:
sin imagen de perfil

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

Publicado por Erasmo Joaquín (1 intervención) el 19/02/2014 22:43:03
Hola Foro!

Estoy tratando de crear un array que contenga datos con la estructura de un árbol (un padre tiene hijos, estos hijos también tienen hijos etc), al ejecutar el código obtengo el error "Commands out of sync; you can't run this command now", leyendo la documentación entiendo que estoy tratando de ejecutar un conjunto de resultados cuando aún no termino con la priemra consulta (así lo entiendo), mi código es el sig. espero me puedan ayudar... gracias

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class RedeemAPI {
    private $db;
    // Constructor - open DB connection
    function __construct() {
        $this->db = new mysqli('localhost', 'futchoco_admin', 'Futcho190867', 'futchoco_futsoft');
       /* verificar la conexión */
       if (mysqli_connect_errno()) {
       	printf("Conexión fallida: %s\n", mysqli_connect_error());
       	exit();
      }
    	$this->db->autocommit(FALSE);
    }
 
    // Destructor - close DB connection
    function __destruct() {
        $this->db->close();
    }
    // Main method to redeem a code
    function redeem() {
    // Check for required parameters
    	if (isset($_POST["id_cliente"]) && isset($_POST["id_sucursal"]))
     	{
 
        // Put parameters into local variables
        $cliente = $_POST["id_cliente"];
        $sucursal = $_POST["id_sucursal"];
        $fecha	= $_POST["fecha"];
 
        // Look up code in database
        $stmt = $this->db->prepare('SELECT a.id_torneo, b.tor_nombre
         FROM calendario a, torneo b
         WHERE a.id_cliente =? AND a.id_sucursal = ? AND
 					date(a. cal_fecha_hora)= date(?) AND
          a.id_cliente = b.id_cliente AND
          a.id_sucursal = b.id_sucursal AND
          a.id_torneo = b.id_torneo') or die(mysqli_error($this->db));
        $stmt->bind_param("iis", $cliente, $sucursal, $fecha);
        $stmt->execute();
        $stmt->bind_result($id_torneo, $tor_nombre);
        $arreglo = array() ;
        $contador = 0;
        while  ($stmt->fetch()) {
 
//Aqui es el primer nivel del array (PADRE), por cada registro PADRE le quiero colgar el siguiente nivel que corresponde a la funcion get_partidos, aqui es donde me marca el error , posteriormente también estos registros hijos deberán de tener otros hijos     	
 
$arreglo[$contador] = array("id_torneox"=>$id_torneo, "torneo_nombre"=>$tor_nombre, "juegos"=>$this->get_partidos($cliente,$sucursal,$fecha,$id_torneo));
        	$contador++;
        }
        $stmt->close();
        // Bail if code doesn't exist
        if ($contador <= 0) {
            sendResponse(400, 'Parametros Cliente/Sucursal invalidos');
            return false;
        }
 				//$return_array = array('arbitros' => $arreglo, 'status' => 1, 'codigo' => 1, 'mensaje' => '');
				sendResponse(200, json_encode($arreglo));
        //sendResponse(200, json_encode($return_array));
        return true;
    	}
    	sendResponse(400, 'Invalid request');
    	return false;
  	}
 
  function get_partidos($cliente,$sucursal,$fecha,$torneo){
    		$stmt2 = $this->db->prepare('SELECT a.id_jornada, a.id_juego, a.cal_fecha_hora, a.id_arbitro, a.cal_estatus, a.cal_default
										FROM calendario a
										WHERE a.id_cliente = ? AND a.id_sucursal = ? AND date(a. cal_fecha_hora) = date(?) AND a.id_torneo = ?') or die(mysqli_error($this->db));
				$stmt2->bind_param("iisi", $cliente, $sucursal, $fecha, $torneo);
        $stmt2->execute();
        $stmt2->bind_result($id_jornada, $id_juego, $cal_fecha_hora, $id_arbitro, $cal_estatus, $cal_default);
        $juegos = array();
        $contador1 = 0;
        while ($stmt2->fetch()) {
        	$juegos[$contador1] = array("id_jornada"=>$id_jornada, "id_juego"=>$id_juego, "cal_fecha_hora"=>$cal_fecha_hora, "id_arbitro"=>$id_arbitro, "cal_estatus"=>$cal_estatus, "cal_default"=>$cal_default);
        	$contador1++;
        }
        return $juegos;
    }
 
}
 
 
// This is the first thing that gets called when this page is loaded
// Creates a new instance of the RedeemAPI class and calls the redeem method
$api = new RedeemAPI;
$api->redeem();
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder