Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/01/2015, 15:25
jfloresga
 
Fecha de Ingreso: enero-2014
Mensajes: 17
Antigüedad: 10 años, 2 meses
Puntos: 0
Ejecutar Store Procedure (MySQL)

Hola

Tengo un SP almacenado en un hostting, tengo un usuario que puede realizar cualquier tipo de consultas, con este mismo usuario estoy ejecutando un SP pero no logro que me regrese ningún registro, para comprobar que es correcto el valor de los parámetros enviados al SP, ejecuto el SP desde Workbench y aquí si obtengo registros. Revisando el log de errores, no existe ningún registro que me notifique de algún error.. qué puede ser?

Código HTML:
<?php

// Helper method to get a string description for an HTTP status code
// From http://www.gen-x-design.com/archives/create-a-rest-api-with-php/ 
function getStatusCodeMessage($status)
{
    // these could be stored in a .ini file and loaded
    // via parse_ini_file()... however, this will suffice
    // for an example
    $codes = Array(
        100 => 'Continue',
        101 => 'Switching Protocols',
        200 => 'OK',
        201 => 'Created',
        202 => 'Accepted',
        203 => 'Non-Authoritative Information',
        204 => 'No Content',
        205 => 'Reset Content',
        206 => 'Partial Content',
        300 => 'Multiple Choices',
        301 => 'Moved Permanently',
        302 => 'Found',
        303 => 'See Other',
        304 => 'Not Modified',
        305 => 'Use Proxy',
        306 => '(Unused)',
        307 => 'Temporary Redirect',
        400 => 'Bad Request',
        401 => 'Unauthorized',
        402 => 'Payment Required',
        403 => 'Forbidden',
        404 => 'Not Found',
        405 => 'Method Not Allowed',
        406 => 'Not Acceptable',
        407 => 'Proxy Authentication Required',
        408 => 'Request Timeout',
        409 => 'Conflict',
        410 => 'Gone',
        411 => 'Length Required',
        412 => 'Precondition Failed',
        413 => 'Request Entity Too Large',
        414 => 'Request-URI Too Long',
        415 => 'Unsupported Media Type',
        416 => 'Requested Range Not Satisfiable',
        417 => 'Expectation Failed',
        500 => 'Internal Server Error',
        501 => 'Not Implemented',
        502 => 'Bad Gateway',
        503 => 'Service Unavailable',
        504 => 'Gateway Timeout',
        505 => 'HTTP Version Not Supported'
    );

    return (isset($codes[$status])) ? $codes[$status] : '';
}

// Helper method to send a HTTP response code/message
function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status);
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}


class RedeemAPI {
    private $db;
    // Constructor - open DB connection
    function __construct() {
        $this->db = new mysqli('localhost', 'usuario', 'password', 'utchoco_futsoft');
       /* verificar la conexión */
       if (mysqli_connect_errno()) {
       	printf("Conexión fallida: %s\n", mysqli_connect_error());
       	exit();
      }
    	$this->db->autocommit(FALSE);
    	$this->db->query("SET NAMES 'utf8'");
    }
        
    // 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"]) && isset($_POST["id_torneo"]) && isset($_POST["id_jornada"])) {
        // Put parameters into local variables
        $cliente = $_POST["id_cliente"];
        $sucursal = $_POST["id_sucursal"];
        $torneo = $_POST["id_torneo"];
        $jornada = $_POST["id_jornada"];
        
        // Look up code in database
        $stmt = $this->db->prepare('CALL tabla_posiciones(?,?,?,?)') or die(mysqli_error($this->db));
        $stmt->bind_param("iiii", $cliente, $sucursal, $torneo, $jornada);
        $stmt->execute();        
        $stmt->bind_result($equ_nombre, $jj, $jg, $je, $jp, $gf, $ge, $dif, $puntos);              
        $arreglo = array() ;    
        $contador = 0;   
        while  ($stmt->fetch()) {
        	$arreglo[$contador] = array("equ_nombre"=>$equ_nombre,"jj"=>$jj,"jg"=>$jg,"je"=>$je,"jp"=>$jp,"gf"=>$gf,"ge"=>$ge,"dif"=>$dif,"puntos"=>$puntos);
        	$contador++;
        }        
        $stmt->close();
        // Bail if code doesn't exist
        if ($contador <= 0) {
            $cuantos = 0;
            $datos[$cuantos] = array("equ_nombre"=>"S/N");
        	$return_array = array('Datos' => $datos,'status' => 1, 'mensaje' => 'No existen registros con los datos proporcionados');
            sendResponse(200, json_encode($return_array));
            return true;
        }
        $this->armarbol($arreglo);
        return true;
    }
    $return_array = array('status' => 1, 'mensaje' => 'Al parecer no se enviaron los parámetros necesarios');
            sendResponse(200, json_encode($return_array));
            return true;
  }
  
  function armarbol(array $general)
  {
  	$datos = array();  
  	//echo "Ingreso a function ";	
  	$cuantos = 0;  
  	foreach ($general as $reg)
  	{  
  		
  	   $datos[$cuantos] = array("equ_nombre"=>$reg["equ_nombre"],"jj"=>$reg["jj"],"jg"=>$reg["jg"],"je"=>$reg["je"],"jp"=>$reg["jp"],"gf"=>$reg["gf"],"ge"=>$reg["ge"],"dif"=>$reg["dif"],"puntos"=>$reg["puntos"] );  
  	   $cuantos++;  		
  	}   
  	
  	 
    $return_array = array('Datos' => $datos, 'status' => 0, 'mensaje' => '');
  	sendResponse(200, json_encode($return_array));
  } 
}

// 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();

?>