Hello friends will see I want to get all the records of a table called CATEGORIES with the fields IDCATEGORIA, NOMBRECATEGORIA, IMAGENCATEGORIA through a Webservice echo in PHP and MYSQL and I show it in a JSON, the problem is that the Webservice only returns me IDCATEGORIA and NOMBRECATEGORIA but IMAGENCATEGORIA does not show it, it is my first time to handle Webservices with PHP, I have only occupied Webservices with Java and as far as Java was needed, I needed to obtain the field IMAGENCATEGORIA from the database and convert that image to base64 and then show it as a string of characters in base64 with the other data already forming the JSON, someone would know how to implement that in my PHP code, here is the PHP file:
Meta.php
/**
* Representa el la estructura de las metas
* almacenadas en la base de datos
*/
require 'Database.php';
class Meta
{
function __construct()
{
}
/**
* Retorna en la fila especificada de la tabla 'meta'
*
* @param $idMeta Identificador del registro
* @return array Datos del registro
*/
public static function getAll()
{
$consulta = "SELECT * FROM meta";
try {
// Preparar sentencia
$comando = Database::getInstance()->getDb()->prepare($consulta);
// Ejecutar sentencia preparada
$comando->execute();
return $comando->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
return false;
}
}
}
?>
get_metas.php
<?php
/**
* Obtiene todas las metas de la base de datos
*/
require 'Meta.php';
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// Manejar petición GET
$metas = Meta::getAll();
if ($metas) {
$datos["estado"] = 1;
$datos["metas"] = $metas;
print json_encode($datos);
} else {
print json_encode(array(
"estado" => 2,
"mensaje" => "Ha ocurrido un error"
));
}
}