How to create Array with DB content

0

I'm trying to create an array with the contents of a tabela of my banco but I do not know how, I tried to do this:

// ATRIBUI UMA CONEXÃO PDO   
$pdo = Conexao::getInstance();
// ATRIBUI UMA INSTÂNCIA DA CLASSE CRUD
$crud = Crud::getInstance($pdo, 'cadAgendaEvento');

// BUSCANDO EVENTOS
$sqlEvento = "SELECT * FROM 'cadAgendaEvento'";

$dados = array();

foreach ($sqlEvento as $Retorno) {                      

    $dados = $Retorno;  

    echo json_encode(
        array(
            "success" => 1,
            "result" => $dados
        )
    );                              
}

I would like to know if this format is correct, apparently it is not returning anything to me.

    
asked by anonymous 03.10.2016 / 23:54

1 answer

0

Because of code similarity, I presume you're using this library: link

If this is the case, just use the method:

public function getSQLGeneric($sql, $arrayParams=null, $fetchAll=TRUE)'

For example:

// BUSCANDO EVENTOS
$dados = $crud->getSQLGeneric($sqlEventos);

At this point the variable $dados will already be an array with the database data.

You can cycle through this data using foreach :

foreach ($dados as $dado) {   
    echo $dado;               
}

If you want to print a json in the way it showed in your code, you do not need to for :

echo json_encode(array(
        "success" => 1,
        "result" => $dados
));
    
04.10.2016 / 00:13