Friday, 16 March 2007
Basic Techniques for Using the MySQLi Interface in PHP 5 |
| |
|
| |
Ben Robinson in a post over the PHP Builder shows you the basic techniques for using the MySQLi interface in PHP 5. He says, this article will illustrate some basic techniques for using the MySQLi interface. He think it is an apt tool to use in PHP 5 because it doesn’t need to include libraries like PEAR, etc; and is compiled into the distribution itself. He says, to start using MySQLi methods right away all you have to do is call the object with the right initialization parameters like the following:
$dblink = new mysqli($dbLoc, $dbUser, $dbPw, $db) or die(mysqli_error($dblink));
He puts an extra error handler in the code so you could see any errors that may result in your connection. He informs that in this case, he is connecting to a root user, no PW, on localhost, using the MySQL world database, so the credentials are quite simple.
He says, you can work on the interface immediately after you have casted $dblink as a new MySQLi object. You should also have a successful database connection and data in your DB to query, he informs. He however, has encapsulated some of the methods available to MySQLi into a class naming them as DB. He shows an example of looping through a basic recordset.
He starts the example by creating a method in the class to store queries in an array by query name. He stores a query for the loop with the help of a code example. With another code, he creates a callback using the inherited MySQLi methods in the DB. In the rest of the article, he illustrates and shows with examples how to use this interface for various purposes to create functions.
In summary, he says, the MySQLi class can be useful for doing repetitive data tasks and it is easier to encapsulate robust methods into your own custom classes. He says, it is a way to begin working with both OO easily inside PHP 5, as well as make your database calls much simpler.
|
| |
|
Read the Post
|
| |
|
|
| |
|
|
| |
|