Json_object php

Hi. I’m trying to recover some data from my php database; however, it doesn’t work whrn I use the JSON_OBJECT. Locally it works, but on infinity free doesn’t work. Moreover, if I use SELECT * instruction also works, so infinityfree doesn’t support JSON_OBJECT. Below is the code.

<?php
	include 'conexion.php';

	if($_REQUEST["rp"] == 'datos'){
		$sql = "SELECT JSON_OBJECT('nombre',Nombre, 'apellido', Apellido, 'correo', Correo) FROM".$_REQUEST["rp"];
    }
	else{ 
		$sql = "SELECT JSON_OBJECT('codigo',Codigo, 'estilo', Estilo, 'precio', Precio, 'oferta', Oferta) FROM".$_REQUEST["rp"];
    }
	$ans = $conn->query($sql);
	if($ans->num_rows >0){
		while ($row = $ans->fetch_array()){
			echo $row[0];
		}
	}
	else{
		echo "No existe";
    }
?>

Our databases servers are still running MySQL 5.6, which does not have JSON support. The upgrade to MySQL 5.7 is being worked on, but until then you won’t be able to use MySQL’s JSON features here.

4 Likes

Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.