Monday, August 15, 2011

mysqli tutorial

moving from procedural coding style to OOP this article telling basic information and maybe helpfull


Getting some info on the result from the mysql database:
 
 $mysqli = new mysqli('localhost','db_user','my_password','mysql'); // Get all the MySQL users and their hosts $sql = "SELECT user, host FROM user"; // If the query goes through if ($result = $mysqli->query($sql)) { // If there are some results if ($result->num_rows > 0) { // Let's show some info echo 'There were '.$result->num_rows.' rows returned. '; echo 'We selected '.$result->field_count.' fields in our query. '; echo 'Our thread ID is '.$mysqli->thread_id.' '; // Ok, let's show the data while ($row = $result->fetch_object()) { echo 'Username: '.$row->user.' :: Host: '.$row->host.' '; } // end while loop } else { echo 'There are no results to display. Odd how we connected to this database and there are no users.'; } // end else } else { // Notice the error would be within the mysqli class, rather than mysql_result printf("There has been an error from MySQL: %s",$mysqli->error); } // end else // Close the DB connection $mysqli->close(); ?>

also read mysql performance

No comments:

Related Posts Plugin for WordPress, Blogger...