PHP – About ORM(Idiorm)

By -



Hi,
PHP idiORM
After been around 1 year i have again started to enjoy with PHP along with Android programming. But this time i am used to develop web-service to be used inside android application. Before 1 year, i have done all the rough coding as i have developed my own DB class and other stuffs. This time i came across one framework/library, i dont know much about this but my one of collegue Mr. Yogesh Prajapati has made me aware about this. You know i have found this very much useful and easy to implement. As per my experience, i have just written 5-10 lines to fetch all records.

Donwloaded link: https://github.com/jrivero/idiorm

About ORM(Idiorm) Query in PHP:

-> ORM stands for Object Relational Mapping.
-> All Idiorm Query start with for_table static method , in which we have to mention the table name to use when making the query.
-> Method calls which add filters and constraints to your query are then strung together.
(i.e. where clause can be strung whenever required.)
-> Finally, the chain is finished by calling either find_one() or find_many(), which executes the query and returns the result.

PHP ORM

PHP ORM - Original image URL: http://tephlon.codesigner.eu/assets/image/PHP-ORM-RDBMS-schema.jpg

 

Fetch Single Record:
—————————
-> find_one() is used to fetch single record.
-> It returns a single instance of ORM class representing the database row you requested or “false” if no matching record is found.

For example:
$student = ORM::for_table(‘student’)->where(‘name’,’paresh’)->find_one();

and if you want to find any record by ‘ID’ then:

$student = ORM::for_table(‘student’)->find_one(5);

Fetch Multiple Records:
—————————
-> find_many() is used to fetch multiple records.
-> It will return an array of ORM class instances or If no rows were found, an empty array will be returned.

For example:
$students = ORM::for_table(‘student’)->find_many();
$students = ORM::for_table(‘student’)->where(‘gender’,’male’)->find_many();

Counting Records:
—————————
-> count() is used to count no. of records

For example:
$number_of_students = ORM::for_table(‘students’)->count();

Equality: where, where_equal, where_not_equal
—————————
Shortcut: where_id_is
—————————

Less than / greater than: where_lt, where_gt, where_lte, where_gte
—————————
There are four methods available for inequalities:

Less than: $student = ORM::for_table(‘students’)->where_lt(‘age’, 10)->find_many();
Greater than: $student = ORM::for_table(‘students’)->where_gt(‘age’, 5)->find_many();
Less than or equal: $student = ORM::for_table(‘students’)->where_lte(‘age’, 10)->find_many();
Greater than or equal: $student = ORM::for_table(‘students’)->where_gte(‘age’, 5)->find_many();

Same as above, there are many operations possible to implement, find those at https://github.com/jrivero/idiorm.

What you feel? isn’t it better and easy to use and to implement? 



Paresh Mayani

Lazy android developer, exploring the horizon of android development since 7 years, currently working as a Technical Lead - Android at Simform Solutions, India. Former Application Architect at KarConnect. He is the Head/Organizer of Google Developers Group (GDG), Ahmedabad

Loading Facebook Comments ...
Loading Disqus Comments ...