Remove more references, and update README

This commit is contained in:
Timothy Warren 2012-10-23 13:40:11 +00:00
parent 27318506d0
commit b1624e2f95
4 changed files with 49 additions and 37 deletions

View File

@ -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);
$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.

View File

@ -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()

View File

@ -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'];
}

Binary file not shown.