How to pass SELECT output to JSON?

Asked

Viewed 25 times

-1

I need to take the result of a query in the Database (made by a select), and insert it into a JSON file to receive the JSON file in Javascript and manipulate the data. I tried something like:

$CampoRecebe = $_POST['CampoCliente'];
$DadosBuscaRecebe = $_POST['DadosBusca'];

$sql = "SELECT ".$CampoRecebe." FROM clientes WHERE ".$CampoRecebe." = '".$DadosBuscaRecebe."'";
$query = mysqli_query($conexao, $sql);
var_dump($query);

$chamaDadosTeste = mysql_query("SELECT ".$CampoRecebe." FROM clientes WHERE ".$CampoRecebe." = '".$DadosBuscaRecebe."'") or die ("Erro na pesquisa".mysql_error());

while ($linha = mysql_fetch_array($chamaDadosTeste))
    
{
    $codigo = $linha['Cod_Cliente'];
    $cargo = $linha['Cargo'];
    $tipo = $linha['Tipo'];
    $nome = $linha['Nome'];


$cliente = array();

$cliente[] = array

(
    'Codigo' => $codigo,
    'Cargo' => $cargo,
    'Tipo' => $tipo,
    'Nome' => $nome
);

echo $ClienteJSON = json_encode ($cliente);

}

But the error occurred:

Fatal error: Uncaught Error: Call to Undefined Function mysql_query() in '' on line 36

Error: Call to Undefined Function mysql_query() in '' on line 36

How can I take the result of a Select and insert it into a JSON file?

  • I believe the problem is much lower level: the server php.ini is not with the mysql module enabled. It is a question more of configuration than programming.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.