nabeel shahzad

Archive for the ‘Fun’ Category

ezSQL Database Library (Improved!)

with 14 comments

Note: I’ve made a dedicated page for ezSQL-related items, you can view it here

I’ve been using ezSQL for a long time, as my “database driver”. It’s an awesome little class, that you can easily use to get database results, and return in different formats. I’ve made a bunch of changes and updates to it, so I thought I’d put them out there and share them.

Along the way, I’ve made some updates and changes to it, to suite my requirements, including format PHP5 support. I’ve updated the error handling/logging, so now you can call:

Java
1
2
$sql->error(); // Get the error string
$sql->errno(); // Get the error number

Respectively after queries to return the “real” status of a query. the debug() function has been added to, so at call time, you can pass to bool whether to display the result on the screen, or pass it back as a string

I’ve also added several utility functions:

Java
1
2
3
4
5
6
7
$sql->quick_select();
$sql->quick_update();
$sql->quick_insert();
// quick_select() example:
$columns = array('column1', 'column2');
$sql->quick_select('table_name', $columns, 'LIMIT 10');

To make it easier to do simple SELECT’s and UPDATEs, and INSERTs.

Another thing it was missing with MySQLi support, so that has been added (though I have not had the time to add support for statements (though that can be accessed rather easily). I had added MSSQL support, but the file has gone AWOL (Icreated and used it for a specific project a while ago). I will update when I get a hold of it.

And another thing I added was a static interface class, which I use all the time on PHP5 projects:

Java
1
2
3
4
5
6
DB::init('mysql');
DB::connect('username', 'password', 'database_name', 'localhost');
// Now anywhere in your script:
$row = DB::get_row('...');
// Or
$results = DB::get_results('...', ARRAY_A);

Makes it much easier to access the database function, without having to do $db = DB::getInstance(), in every single function to get a singleton object of the database. Since that’s for PHP5 only, the whole library has been updated for PHP 5 support, with public/private functions and constructors/destructors as well.

I also condensed it to just one include() now, just keep all the files in the same place (include ‘…/DB.class.php’). From that you can either use the static class, or declare a new ezSQL object.

I also added in phpDoc blocks on all the functions, since IntelliSense is awesome and really helpful.

I hope these improvements make it easier for everyone. Of course, the original credit goes to Justin Vincent. There are some docs and examples here as well.

You can download it from here

Written by Nabeel

February 3rd, 2009 at 11:52 am

Posted in Fun,General,php,Projects

Airplane Movie Quotes

with one comment

I just did a quick thing for the phpVMS admin panel, displaying random quotes from the movie Airplane! in the footer. Just call the function randquote(), and it’ll return the string, so you can do whatever you want with it.

And don’t call me Shirly…

Click to download it (zip file)

Written by Nabeel

January 2nd, 2009 at 12:26 pm

Posted in Fun,General,phpVMS

Tagged with , ,