Skip to content

Instantly share code, notes, and snippets.

@geovanerocha
Created September 25, 2012 16:08
Show Gist options
  • Save geovanerocha/3782827 to your computer and use it in GitHub Desktop.
Save geovanerocha/3782827 to your computer and use it in GitHub Desktop.
Using PHP Data Object.
$db = new PDO('mysql:host=localhost:3306;dbname=db','root','');
$stm = $db->prepare('SELECT * FROM db.usuario');
$result = $stm->execute();
$usuarios = array();
while($row = $stm->fetchObject())
{
$usuarios[] = $row->nome;
}
/*
@ Alternate syntax;
*/
foreach($usuarios as $id => $nome):
echo 'Usuario ' .strtolower($nome). '<br/>';
echo 'ID '.$id.'<p/>';
endforeach;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment