From b1624e2f9599ad661505d16eecd42e39a6c982d7 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 23 Oct 2012 13:40:11 +0000 Subject: [PATCH] Remove more references, and update README --- README.md | 22 +++++++++++- classes/db_pdo.php | 1 + classes/query_builder.php | 63 +++++++++++++++------------------- tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 6ba32db..6201a91 100644 --- a/README.md +++ b/README.md @@ -80,4 +80,24 @@ To retreive the results of a query, use the PDO method [fetch](http://php.net/ma $query = $db->get('table_name'); - $results = $query->fetchAll(PDO::FETCH_ASSOC); \ No newline at end of file + $results = $query->fetchAll(PDO::FETCH_ASSOC); + + +### Inserting / Updating + +An example of an insert query: + + $query = $db->set('foo', 'bar') + ->set('foobar', 'baz') + ->where('foo !=', 'bar') + ->insert('table'); + +An example of an update query: + + $query = $db->set('foo', 'bar') + ->set('foobar', 'baz') + ->where('foo !=', 'bar') + ->update('table'); + +The `set` method can also take an array as a paramater, instead of setting individual values. + diff --git a/classes/db_pdo.php b/classes/db_pdo.php index 491ae32..51a26e1 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -446,6 +446,7 @@ abstract class DB_PDO extends PDO { /** * Return the number of rows returned for a SELECT query * + * @see http://us3.php.net/manual/en/pdostatement.rowcount.php#87110 * @return int */ public function num_rows() diff --git a/classes/query_builder.php b/classes/query_builder.php index 80550a7..1c13cef 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -311,7 +311,7 @@ class Query_Builder { $fields_array = array_map('trim', $fields_array); // Split on 'As' - foreach ($fields_array as $key => &$field) + foreach ($fields_array as $key => $field) { if (stripos($field, 'as') !== FALSE) { @@ -586,7 +586,7 @@ class Query_Builder { $where = $this->_where($key, $val); // Create key/value placeholders - foreach($where as $f => &$val) + foreach($where as $f => $val) { // Split each key by spaces, in case there // is an operator such as >, <, !=, etc. @@ -659,7 +659,7 @@ class Query_Builder { // Array or object, loop through and add to the where array elseif ( ! is_scalar($key)) { - foreach($key as $k => &$v) + foreach($key as $k => $v) { $where[$k] = $v; $this->values[] = $v; @@ -684,7 +684,7 @@ class Query_Builder { $where = $this->_where($key, $val); // Create key/value placeholders - foreach($where as $f => &$val) + foreach($where as $f => $val) { // Split each key by spaces, in case there // is an operator such as >, <, !=, etc. @@ -846,7 +846,7 @@ class Query_Builder { // Object or array elseif ( ! is_scalar($key)) { - foreach($key as $k => &$v) + foreach($key as $k => $v) { $this->set_array_keys[] = $k; $this->values[] = $v; @@ -954,7 +954,7 @@ class Query_Builder { $order_clauses = array(); // Flatten key/val pairs into an array of space-separated pairs - foreach($this->order_array as $k => &$v) + foreach($this->order_array as $k => $v) { $order_clauses[] = $k . ' ' . strtoupper($v); } @@ -1279,15 +1279,7 @@ class Query_Builder { $this->from($table); } - $sql = $this->_compile(); - - // Reset the query builder for the next query - if ($reset) - { - $this->reset_query(); - } - - return $sql; + return $this->_get_compile('select', $table, $reset); } // -------------------------------------------------------------------------- @@ -1301,15 +1293,7 @@ class Query_Builder { */ public function get_compiled_insert($table, $reset=TRUE) { - $sql = $this->_compile("insert", $table); - - // Reset the query builder for the next query - if ($reset) - { - $this->reset_query(); - } - - return $sql; + return $this->_get_compile('insert', $table, $reset); } // -------------------------------------------------------------------------- @@ -1323,15 +1307,7 @@ class Query_Builder { */ public function get_compiled_update($table='', $reset=TRUE) { - $sql = $this->_compile('update', $table); - - // Reset the query builder for the next query - if ($reset) - { - $this->reset_query(); - } - - return $sql; + return $this->_get_compile('update', $table, $reset); } // -------------------------------------------------------------------------- @@ -1345,7 +1321,22 @@ class Query_Builder { */ public function get_compiled_delete($table="", $reset=TRUE) { - $sql = $this->_compile("delete", $table); + return $this->_get_compile('delete', $table, $reset); + } + + // -------------------------------------------------------------------------- + + /** + * Helper function for returning sql strings + * + * @param string $type + * @param string $table + * @param bool + * @resturn string + */ + protected function _get_compiled($type, $table, $reset) + { + $sql = $this->_compile($type, $table); // Reset the query builder for the next query if ($reset) @@ -1463,7 +1454,7 @@ class Query_Builder { // Set the where string if ( ! empty($this->query_map)) { - foreach($this->query_map as &$q) + foreach($this->query_map as $q) { $sql .= $q['conjunction'] . $q['string']; } @@ -1478,7 +1469,7 @@ class Query_Builder { // Set the having string if ( ! empty($this->having_map)) { - foreach($this->having_map as &$h) + foreach($this->having_map as $h) { $sql .= $h['conjunction'] . $h['string']; } diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 761b13d2aba7cee15a748ab762e7ef3b6717c3a3..9f26a950c6d5f24e26fe8e53bb30f239ae6fffb6 100644 GIT binary patch delta 2137 zcmb7_T}V_x6vxlp4_$XO$Bz)jWLNL{ffNc#8cS&`v6R>ni!IfISpAMz z2nq%Yf+%{95+#Uw529Xri5@h}2Nf-d@Z~~hW<2iZE@>lo$N!zL|8M4;xw%|#F4sHC zV6f+D4DvftFI-=g`J&txAzxI?iLfKsg?Tp;uCKU1Bx>gyyTYH#{GRY!4|iVN9IP~R)9)Co zgIN{>$Bw|P6M=h9D)pfJx%D-YD8cflUv`Z6Aq{JF#r$m46gZhr~bjD~IN#09C8 zAhn1zV@N9&k@TD*ZMnh%M4)0|Yl>i1U@7yiGLJQB4UcW42{ygepJ3B_gH7jQ>r23< zAR z_KE;T3dzvnh$gGA4O9kE32EzcWsx_r5zW*g0+WiSi(xZ+srJ)6{Wu%4#Vj7kPwTv; zT<2hRM4uKLHP+n#%8hlhLTN@?M;dM%X^n=%k~^#?ce9@SAL~hdEM@zUv*9oMNwfVr zu}&HWOsqP?K%OXjNE@b!ENRVD6F_1ILt;0E#Q!iPbQZ~L>b6Um964cfL{6{r)?r%R z1P5%pA@|g-)8I0Lp+dKKu?=mf!67!3k9B!^jW^;871yj%-dW>asPaL3T<@C9uJYJ0 zO-U9=Q~Z+F@roAcuBGcHUSJ_^ET{`KSt8MBD8&~=_rGq@xZc457%g5T3W$-E2H|{F2nF%CDWZle85gA&w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