
ezSQL - How To Use and Download?
ezSQL is an open source PHP database class written by Justin Vincent used on over 100k websites and is the backbone of many open source projects such as WordPress. The class makes it ridiculously easy to use mySQL, Oracle8, SQLite (PHP), within your PHP script. With excellent debug function, ezSQL can dramatically decrease development time and in most cases will streamline your code and make things run faster.
For small to medium sized enterprises where frameworks like Symfony, Codeigniter, CakePHP, Zend etc. arent probably used much, ezSQL comes handy instead of using the traditional mysql_query to query the database.
Imagine a scenario where you used SQL for long years and suddenly, you have to migrate to Oracle or PostgreSQL or rather, even MS-SQL?
The reasons of migration can be self explanatory:
- If you’re working for a client, the client is interested in expanding & supporting more advanced & premium technologies.
- The other way round, if you’re working for yourself, you started with SQL not thinking too large about your project, but destiny kicks & you’re all set to go big!You have to take care of huge database & server issues then.
Above scenarios gives you a nightmare to think actually about rewriting your code completely just to be able to make your code compatible with a database.
Thanks to ezSQL, we now have a solution!ezSQL allows you to work with various databases very easily, though, it does not support differences in SQL syntax implementations among different databases.
Why use ezSQL?
- You want to produce clean code.
- You want to reduce development time.
- Debugging is easy.
- Migration to various databases is easy.
Download & Install ezSQL:
1. Click here to Download ezSQL from Justin Vincent’s website.
2. Create a ezSQL Object :
include_once “../shared/ez_sql_core.php”;
include_once “ez_sql_mysql.php”;
$db = new ezSQL_mysql(‘db_user’,'db_password’,'db_name’,'db_host’);
Example Queries:
1. Insert query :
$db->query("INSERT INTO users (id, name, email) VALUES (NULL,'IIPL','webmaster@ithinkinfotech.com')");
2.Update query :
$db->query("UPDATE users SET name = 'iThink Infotech' WHERE id = 4");
3. Select a row:
$user = $db->get_row("SELECT name, email FROM users WHERE id = 4"); echo $user->name; echo $user->email;
4.Select a single row:
$var = $db->get_var("SELECT count(*) FROM users"); echo $var;
5.Select multiple results:
$results = $db->get_results("SELECT name, email FROM users"); foreach ( $results as $user ) { echo $user->name; echo $user->email; }
6.Select a column:
foreach ( $db->get_col("SELECT name,email FROM users",0) as $name ) { echo $name; }
7.Debug:
$db->debug();
Credits:
1. Sincere thanks to Justin Vincent for giving us ezSQL.
2. Credits to Catswhocode for giving us the first hand information about ezSQL.