Gumbo_Query



Query Class

This class was designed to provide a central location for executing common queries (select,insert,update,delete) on a database. The current implementation works with a PDO object. Once the PDO object is created, it is assigned to the Query class.

"Is this abstracting the abstraction layer?" Probably. This is meant to wrap specific methods inside various DB classes that abstract database functionality (PDO, ADODB, PEAR_DB, Zend_DB, etc.). The problem was switching between them. Each perform the same tasks, except the interfaces are different. Therefore, having to switch between ADODB and PDO could become a large chore. Imagine searching through thousands of lines of code to find the ADODB calls and switching to PDO. (I've had to do it twice on the same project, it sucks). By using this class, I was able to make changes to the DB system in one place, while the application code remained untouched.

This class is not going to be further extended. There will not be a Gumbo_Query_PDO, Gumbo_Query_ADODB, etc. Since a large majority of applications will use one database connection, I feel it's better just to have one implementation. In order to use other DB systems, simply change the implementation for your specific needs (place inside the 'Custom' directory). The system will load the 'custom' class first, ignoring this one. Since there is only one, any changes would be made to the implementation, not the application.

(This topic is certainly up for debate, so feel free to post your opinion on the SourceForge Project Forum)

Author(s): Michael Luster <mluster79@yahoo.com>
License:New BSD License
Copyright:Copyright (c) 2007, iBayou, Michael Luster
Link:http://sourceforge.net/projects/phpgumbo
Version:0.0.1

Implements interfaces:

Class Variables

static Gumbo_Interface_Query $_instance =  null [line 64]
mixed $_db [line 67]
string $_token =  "?" [line 69]

Class Methods

public static mixed execute ( string $sql, [array $params], [string $name] ) [line 145]

Executes the given query and returns the results

This is a Bridge between the DB interface and the Item class. It will execute a sinle query and return the results. If a SELECT is performed, then a single associative array representing a record is returned. If an INSERT is performed, then the new insert ID is returned. UPDATE and DELETE queries will not return anything.

Parameter(s):

  • (string) $sql
  • (array) $params :: list of parameters for the prepare method
  • (string) $name :: sequence/column name for returning lastInsertId()
  • todo:  implementation for DB classes
  • throws:  Gumbo_Exception

[ Top ]
public static mixed getDb ( ) [line 278]

Returns the DB Resource or Object


[ Top ]
public static string getToken ( ) [line 286]

Returns the token character


[ Top ]
public static Gumbo_Query instance ( ) [line 82]

Singleton Method


[ Top ]
public static string prepare ( string $sql, [array $params], [string $token] ) [line 202]

Prepares a query by substituting a token character with parameter values

Parameter(s):

  • (string) $sql
  • (array) $params :: list of parameters
  • (string) $token :: replacement token character
  • throws:  Gumbo_Exception

[ Top ]
public static array results ( string $sql, [array $params] ) [line 100]

Returns an array of Items with the results of a "SELECT ... " query

Parameter(s):

  • (string) $sql :: query to execute
  • (array) $params :: token parameter values
  • throws:  Gumbo_Exception
  • precondition:  getDb()

[ Top ]
private Gumbo_Query __construct ( ) [line 76]

Constructor


[ Top ]
public void setDb ( mixed $db ) [line 248]

Sets the DB Object Reference

Parameter(s):

  • (mixed) $db

[ Top ]
public void setToken ( string $token ) [line 257]

Sets the token character

Parameter(s):

  • (string) $token
  • throws:  Gumbo_Exception

[ Top ]