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 f84a9d6..6a52641 100755 Binary files a/tests/test_dbs/FB_TEST_DB.FDB and b/tests/test_dbs/FB_TEST_DB.FDB differ diff --git a/tests/test_dbs/test_sqlite.db b/tests/test_dbs/test_sqlite.db index f2f978a..af75544 100644 Binary files a/tests/test_dbs/test_sqlite.db and b/tests/test_dbs/test_sqlite.db differ