PHP Classes

PDO Query Builder: Compose and execute SQL queries using PDO

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-10 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 694 This week: 2All time: 4,712 This week: 96Up
Version License PHP version Categories
query-builder-pdo 0.19MIT/X Consortium ...5PHP 5, Databases
Description 

Author

This class can compose and execute SQL queries using PDO.

It extends the PDO class to provide a fluent interface to compose SQL queries of several types and a range of query parameter clauses.

Currently it can compose and run SQL INSERT, REPLACE, UPDATE and DELETE queries.

It can also compose SQL clauses for LEFT JOIN, HAVE, WHERE, GROUP BY, ORDER, LIMIT and OFFSET.

The query results may be cached using memcache.

Picture of Gnce Bektas
  Performance   Level  
Name: Gnce Bektas <contact>
Classes: 1 package by
Country: Turkey Turkey
Age: 37
All time rank: 284247 in Turkey Turkey
Week rank: 106 Up4 in Turkey Turkey Up

Recommendations

Details

<h1>Query builder for PDO with memcache support</h1>

It’s developed as fluent interface design. You can easily access to database just by using select functions anywhere you want.

<b>Build query:</b> select(‘users’)->where(‘user_id = “’. $user_id .’” ’)->limit(1);

<b>Run query:</b> select(‘users’)->where(‘user_id = “’. $user_id .’” ’)->limit(1)->run;

<b>Fetch result</b> select(‘users’)->where(‘user_id = “’. $user_id .’” ’)->limit(1)->result();

Easy to read & write, isn’t it? You can use helper functions insert(), replace(), update(), delete() and select() in everywhere including functions without calling global $pdo. For other features please call global $pdo variable.

Let’s look it deeply with examples… For examples I will use ‘users’ as table name of users, and ‘langs’ for table name of available languages

<b>find(‘users’, 1)</b> Returns just one row of selected table with the match of first column

<b>select(‘users’)</b> Returns the row of selected table It means “select from” to change use ->which() after select()

<b>left(‘langs ON langs.lang_id = users.lang_id’)</b> LEFT JOIN statement for select, usage is; select(‘users’)->left(‘langs ON langs.lang_id = users.lang_id’)->results();

<b>insert(‘users’)->values(array)</b> insert(‘users’)->values(array(‘user_name’=>’Jon Snow’));

<b>replace(‘users’)->values(array)</b> replace(‘users’)->values(array(‘user_name’=>’Jon Snow’));

<b>update(‘users’)->values(array)</b> update(‘users’)->values(array(‘user_name’=>’Jon Snow’))->where(‘user_id = 1’);

<b>where()</b> select(‘users’)->where(‘user_id = 1’)->result();

<b>* which()</b> I know which statement is a little bit odd but it’s simple and points * for select queries like; select(‘users’)->which(‘user_name, users.lang_id AS lang_id)

<b>group()</b> select(‘users’)->group(‘lang_id’);

<b>have()</b> select(‘users’)->have(‘lang_id’);

<b>order()</b> ->order(‘user_id ASC’);

<b>limit()</b> ->limit(10);

<b>offset()</b> ->offset(10);

<b>column() – final function </b> column(‘users’)

<b>write() – final function</b> shows query

<b>* run() – final function</b> ->run();

<b>* result() – final function</b> ->result();

<b>* results() – final function</b> ->results();

<b>results_pairs() – final function (Beta)</b> Gather results as pair, is very useful when working with lists ->results_pairs();

<b>PS:</b> You can send arrays as parameters to insert or update a column, query builder will automatically detect and change it into json


  Files folder image Files  
File Role Description
Files folder imageexamples (1 file)
Accessible without login Plain text file pdo.php Class Class source
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file examples.php Example examples

 Version Control Unique User Downloads Download Rankings  
 100%
Total:694
This week:2
All time:4,712
This week:96Up