Created
May 16, 2013 14:27
-
-
Save melissacabral/5592112 to your computer and use it in GitHub Desktop.
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
<?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