Hi everyone.
I’m not expert PHP developer.
I have one WebService write on PHP and I have one error in this line
`while ($row = $stmt->fetch_object()) {
$arreglo[$contador] = array(“equ_nombre”=>$row->equ_nombre,”jj”=>$row->jj,”jg”=>$row->jg,”je”=>$row->je,”jp”=>$row->jp,”gf”=>$row->gf,”ge”=>$row->ge,”dif”=>$row->dif,”puntos”=>$row->puntos);
Just after execute
`$stmt = $this->db->query(‘CALL tabla_posiciones(@par_cliente,@par_sucursal,@par_torneo,@par_jornada)’) or die(mysqli_error($this->db));
`
What’s wrong?
This the complete code …
`
<?php
// Helper method to get a string description for an HTTP status code
// From
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’, ‘futchoco’, ‘987654’, ‘futchoco_futsoft’);
/* verificar la conexión */
if (mysqli_connect_errno()) {
printf(“Conexión fallida: %sn”, 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(‘SET @par_cliente := ?’);
$stmt->bind_param(‘i’, $cliente);
$stmt->execute();
$stmt = $this->db->prepare(‘SET @par_sucursal := ?’);
$stmt->bind_param(‘i’, $sucursal);
$stmt->execute();
$stmt = $this->db->prepare(‘SET @par_torneo := ?’);
$stmt->bind_param(‘i’, $torneo);
$stmt->execute();
$stmt = $this->db->prepare(‘SET @par_jornada := ?’);
$stmt->bind_param(‘i’, $jornada);
$stmt->execute();
$stmt = $this->db->query(‘CALL tabla_posiciones(@par_cliente,@par_sucursal,@par_torneo,@par_jornada)’) or die(mysqli_error($this->db));
$arreglo = array() ;
$contador = 0;
while ($row = $stmt->fetch_object()) {
$arreglo[$contador] = array(“equ_nombre”=>$row->equ_nombre,”jj”=>$row->jj,”jg”=>$row->jg,”je”=>$row->je,”jp”=>$row->jp,”gf”=>$row->gf,”ge”=>$row->ge,”dif”=>$row->dif,”puntos”=>$row->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’ => 0, ‘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’ => 1, ‘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();
?>
`