From 39d70bf808ae59dd0019df94fe2a02c2231323f5 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 15 Mar 2012 12:02:26 -0400 Subject: [PATCH] Updated README, updated query_builder class to accept an array as well as an object --- README.md | 46 +++++++++++++++++++++++++++++++++- query_builder.php | 13 ++++++++++ tests/test_dbs/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes tests/test_dbs/test_sqlite.db | Bin 3072 -> 3072 bytes 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 048d5fa..d8a8f34 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,47 @@ # Query -A query builder/abstraction layer. \ No newline at end of file +A query builder/abstraction layer. + +## Databases Supported + + * Firebird + * MySQL + * PostgreSQL + * SQLite + * Others, via ODBC + +## Requirements + * Pdo extensions for the databases you wish to use (unless it's Firebird, in which case, the interbase extension is required) + + +## Connecting + +Create a connection array or object similar to this: + + 'mysql', + 'host' => 'localhost', + 'user' => 'root', + 'pass' => '', + 'port' => '3306', + 'database' => 'test_db', + + // Only required + // SQLite or Firebird + 'file' => '/path/to/db/file', + ); + + $db = new Query_Builder($params); + +The parameters required depend on the database. + +### Running Queries +Query uses the same interface as CodeIgniter's [Active Record class](http://codeigniter.com/user_guide/database/active_record.html). However, it does not implement the `select_` methods, `count_all_results`, or `count_all`. + +To retreive the results of a query, use the PDO methods `fetch` and `fetchAll`. + + $query = $this->db->get('table_name'); + + $results = $query->fetchAll(PDO::FETCH_ASSOC); \ No newline at end of file diff --git a/query_builder.php b/query_builder.php index 803b9fd..3bf561f 100644 --- a/query_builder.php +++ b/query_builder.php @@ -62,6 +62,19 @@ class Query_Builder { */ public function __construct($params) { + // Convert array to object + if (is_array($params)) + { + $p = new StdClass(); + + foreach($params as $key => $val) + { + $p->$key = $val; + } + + $params = $p; + } + $params->type = strtolower($params->type); $dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql'; diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB index f84a9d65ddca2c8394283d0b361f7f10096fe650..6a52641bbd9d597278e52025e2de5a8723f0b7a9 100755 GIT binary patch delta 395 zcmYk0%}YW-5Wr{mJ=5MGO$IMW1kFm3J~Ze<3O#t2gy>R&*Pu)1gdP%m4}v*(>ObfM z^imx=+C2!wXL%{;Kd^l-BWKxJelx>w)^T!~FoKs*&FT0;x~U2cdJ`zE9NdrW&M3D3Xc{MW&*Fq6tMoMIl9#EwW4!#daWWH3Q~w zI4s^)jx3e6T3Ix2iqD>BEDi+f&5M5JTZCcHh{Lim4Y477teqVqmE^yezgb4DQiz}kQRToQQm#=k^JAKTE9sY80fn)EOlG`?S zx)|fL0Y><^k2C9=Bc0STPxr?jjWhVXak6T2xra%9(>nfi(c-xQM)|RaDUspI2bS9P IK3*LD0OQ?Lc>n+a delta 413 zcmYk2y-xx`5XEQi4$&J8>lYL@Ag3rqbC+n;(%9Hb)gvQFs*n48Kg;o}33K|=G zKN9HF(n@1XMNZTN34eiwdxt19+1>o!?z~N&>pHIMtRpPhhcWmsL9YHw{+Wpa*lGc2 zSgHbSExe>QhuRMWXsYu8pxQIhyF~srQWR346q*#e6owQbDSD&`OVKMuUs;%jK&KLl zo23xyH`!fN+Gg1%<9hAEH|eTvj6lCW5h&l<0L%kW7(Gg;50f6vpv_s2R&bUtl*rY0N^|p#Om28I S7T9R%C_mRIQOVWmD)$2bK2wJP diff --git a/tests/test_dbs/test_sqlite.db b/tests/test_dbs/test_sqlite.db index f2f978a3a96b6e22faa85cc31eba82bea466d448..af755449d764688b546f5e2ee8709975aea2a9f7 100644 GIT binary patch delta 17 YcmZpWXpop7%_uZc#+gxQW5NP%04b3Kt^fc4 delta 17 YcmZpWXpop7&B!%T#+i|8W5NP%04W&+o&W#<