sandeep529 Posted April 10, 2009 Share Posted April 10, 2009 Hi all, If you ever skipped checking for an existing username ,just before adding a new username to a table,just because of the trouble of writing the required query, Then this class might solve some problems for you . Consider a database table to be two dimensional php array.The first index of the array being the primary key field,Second index,the column names .Now ,when you want to store something in an array ,you dont write small scripts(like SQL) ,instead you write 1. $array[10]['name']='user_1'; Then why,every time you want to get or set ,the `name` field for n'th row from the `user` table ,you have to write an SQL query to do that?I mean you could express the requirement, which is to get the name field from 10th row of user table by using a simpler syntax ,a syntax native to php.like 2. $name=$user[10]->name; This class exports a syntax that enables you to do just that,and more. It allows you to specify what you want from your database with a lot fewer words. I call it a high level query language because ,It does to SQL what C does to Assembly language. A few things this class can do for you... 1.Reduces the code required to carryout an sql operation for example to insert a row into a table `user` you can do as 1. $db->user= array('name'=>'user_1','no'=>45); to get the `name` column from table user with primary key value 10 1. $name=$db->user(10)->name; to update name column from table user with primary key value 10 ,to 'user_2' 1. $db->user(10)->name ='user_2' ; 2.Reduces errors by eliminating the strings inside strings ie, constructs Like "name='user' ",this is bad because a missing single quote in a double quoted string is hard to detect. For example,to get the id of the user with name='user' from table user , 1. $id=$db->user->name('user')->id; now if you miss that single quote around user ,the editor ,if it supports syntax checking will find that out as soon as you finish typing it... 3.Automatically renames columns in a join This feature is helpful if two tables in join contains the fields with same name,ex id field.. 1. $rows=$db->_join->user('u')->comments('c')->end; 2. echo $rows->u_id(10)->u_name; 3. // the name of user with id =10 from user table,aliased as 'u' becomes u_name.The `id` in user table aliased as 'u' becomes u_id. 4. echo $rows->u_id(10)->c_comment 5. // the comment field in comments table becomes c_comment. 4.Automatically escapes the double quotes in string values . The class only escapes a double quote only if t has not already been escaped.ie it does not do the usuall get_magic_quotes to find out wether the string has been already escaped. Please download the class from the attachment.See the howto.html in the zip file for more features,and there are lots of them...... please let me know of your comments , even if you dont like it... Regards, Max [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/153467-a-higher-level-query-language-in-php5/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.