ezSQL is a widget that makes it ridiculously easy for you to use database(s) within your PHP scripts. It is fully documented with many easy to understand examples. mySQL version available, Oracle coming soon.
By : jv
ezSQL is a widget that makes it ridiculously easy for you to use database(s) within your PHP scripts.
This widget is a php file that you include at the top of your script. Then, instead of using std php database functions listed in the php manual, you use a much smaller (and easier) set of ezSQL functions.
ezSQL can dramatically increase development time and in most cases will streamline your code and make things run faster as well as making it very easy to debug and optimise your database queries.
The debug system draws a neat table showing exactly what your query was and results are.
Please read through these examples to see how easy using databases can be using ezSQL.
------------------------------------------------------- Example 1 -------------------------------------------------------
// Select multiple records from the database.. $results = $db->get_results("SELECT name, email FROM users");
foreach ( $results as $user ) { // Access data using object syntax echo $user->name; echo $user->email; }
---------------------------------------------------- Example 2 ----------------------------------------------------
// Get one row from the database.. $user = $db->get_row("SELECT name,email FROM users WHERE id = 2");
echo $user->name; echo $user->email;
---------------------------------------------------- Example 3 ----------------------------------------------------
// Get one variable from the database.. $var = $db->get_var("SELECT count(*) FROM users");
echo $var;
---------------------------------------------------- Example 4 ----------------------------------------------------
// Insert into the database $db->query("INSERT INTO users (id, name, email) VALUES (NULL,'Justin','jv@foo.com')");
---------------------------------------------------- Example 5 ----------------------------------------------------
// Update the database $db->query("UPDATE users SET name = 'Justin' WHERE id = 2)");
---------------------------------------------------- Example 6 (for debugging) ----------------------------------------------------
// Display last query and all associated results $db->debug();
---------------------------------------------------- Example 7 (for debugging) ----------------------------------------------------
// Display the structure and contents of query results (or any variable) $results = $db->get_results("SELECT name, email FROM users");
$db->vardump($results);
---------------------------------------------------- Example 8 ----------------------------------------------------
// Get 'one column' (based on index) from a query.. $names = $db->get_col("SELECT name,email FROM users",0)
foreach ( $names as $name ) { echo $name; }
// Get another column from the previous (cached) query results.. $emails = $db->get_col(null,1)
foreach ( $emails as $email ) { echo $email; }
---------------------------------------------------- Example 9 ----------------------------------------------------
// Map out the full schema of any given database..
$db->select("my_database");
foreach ( $db->get_col("SHOW TABLES",0) as $table_name ) {
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.