Created
September 25, 2012 16:08
-
-
Save geovanerocha/3782827 to your computer and use it in GitHub Desktop.
Using PHP Data Object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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