You can try the code below;
$host = 'localhost'; // endereço do servidor de banco de dados.
$dbname = 'seu_banco_de_dados'; //nome de sua base de dados
$user = 'root'; // seu usuário do banco
$pass = ''; // sua senha do banco
$db = new PDO('mysql:host='.$host.';dbname='.$dbname,$user,$pass);
$lista = $db->prepare(queryMes($ano,$ibge));
$lista->execute();
$item = $lista->fetchAll(PDO::FETCH_ASSOC);
echo $item[3]['nome'];
Or you can use the for to list...
$host = 'localhost'; // endereço do servidor de banco de dados.
$dbname = 'seu_banco_de_dados'; //nome de sua base de dados
$user = 'root'; // seu usuário do banco
$pass = ''; // sua senha do banco
$lista = $db->prepare(queryMes($ano,$ibge));
$lista->execute();
$item = $lista->fetchAll(PDO::FETCH_ASSOC);
foreach($item as $info) {
echo $info['nome']."<br/>";
}
Hi Italo this $db is a PDO instance??
– Hiago Souza
what is
$db
? what isqueryMes
? code missing before those lines.– novic
is a yes instance
– Italo Rodrigo
May
echo $item[3]['nome'];
– rray
@Virgilionovic query works well, is that I simplified the code above. the variable $item should list all my items
– Italo Rodrigo
@Italorodrigo do not simplify, put, really what you are doing, everything relevant and in the details.
– novic
I will edit the question
– Italo Rodrigo
use the
print_r
orvar_dump
to know if it comes as array or object. If it is a PDO instance, it must come as object.– William Aparecido Brandino
edited and posted the code I’m using now
– Italo Rodrigo
That
$lista->execute()
doesn’t make any sense. Gives aprint_r($obito)
and ask the question, so everyone knows the structure of it.– rray
thanks to all, I managed to solve
– Italo Rodrigo