Skip to content

Instantly share code, notes, and snippets.

@melissacabral
Created May 16, 2013 14:27
Show Gist options
  • Save melissacabral/5592112 to your computer and use it in GitHub Desktop.
Save melissacabral/5592112 to your computer and use it in GitHub Desktop.
<?php
//creates db object
$db = new mysqli('localhost', 'user', 'pass', 'demo');
if($db->connect_errno > 0){
die('Unable to connect to database');
}
//set up query
$query = 'SELECT *
FROM posts';
//run it and confirm there are results to show
if($result = $db->query($query)):
echo 'Total results: ' . $result->num_rows . '<br />';
//echo 'Total rows updated: ' . $db->affected_rows;
while($row = $result->fetch_assoc()):
?>
<p>
<?php echo $row['body'] ;?>
</p>
<?php
endwhile;
$result->free();
else:
die('There was an error running the query [' . $db->error . ']');
endif;
$db->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment