Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mysqli = new mysqli('localhost','user','pass','db');
- //This is where we will query the database and pull using the cities/states SELECT statement
- // If the result returns true
- if ($result = $mysqli->query("SELECT * FROM users")) {
- // So the result returned true, let's loop and print out each city.
- // The number of rows returned is assigned to the property "num_rows" in the mysql_result class
- echo 'There are '.$result->num_rows.' users within the user database.
- ';
- // The "fetch_object()" method is the equivalent of the old mysql_fetch_object() function. It allows access to the returned rows within the resouce object ($result in this case).
- while ($row = $result->fetch_object()) {
- echo 'Email: '.$row->emailaddress.'
- ';
- }
- } else {
- // Notice below that the errors are still contained within the mysqli class. This means that each result will affect a single "error" property. In otherwords, if your result fails, the error returned from MySQL is assigned to the property "error".
- // This means the query failed
- echo $mysqli->error;
- } // end else
- $mysqli->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement