Skip to content
Browse files

Merge branch '3.2/develop' into 3.2/master

  • Loading branch information...
2 parents f0944e8 + d7ce493 commit a11f46478021efd653b882b59a018fd53da98bdd @zombor zombor committed Aug 23, 2012
Showing with 231 additions and 210 deletions.
  1. +2 −2 classes/config/database.php
  2. +1 −1 classes/config/database/reader.php
  3. +1 −1 classes/config/database/writer.php
  4. +1 −1 classes/database.php
  5. +1 −1 classes/database/exception.php
  6. +1 −1 classes/database/expression.php
  7. +1 −1 classes/database/mysql.php
  8. +1 −1 classes/database/mysql/result.php
  9. +1 −1 classes/database/pdo.php
  10. +1 −1 classes/database/query.php
  11. +1 −1 classes/database/query/builder.php
  12. +1 −1 classes/database/query/builder/delete.php
  13. +1 −1 classes/database/query/builder/insert.php
  14. +1 −1 classes/database/query/builder/join.php
  15. +1 −1 classes/database/query/builder/select.php
  16. +1 −1 classes/database/query/builder/update.php
  17. +1 −1 classes/database/query/builder/where.php
  18. +1 −1 classes/database/result.php
  19. +1 −1 classes/database/result/cached.php
  20. +1 −1 classes/db.php
  21. +3 −3 classes/kohana/config/database.php
  22. +15 −2 classes/kohana/config/database/reader.php
  23. +1 −1 classes/kohana/config/database/writer.php
  24. +29 −24 classes/kohana/database.php
  25. +1 −1 classes/kohana/database/exception.php
  26. +1 −1 classes/kohana/database/expression.php
  27. +3 −5 classes/kohana/database/mysql.php
  28. +1 −1 classes/kohana/database/mysql/result.php
  29. +4 −4 classes/kohana/database/pdo.php
  30. +14 −14 classes/kohana/database/query.php
  31. +11 −11 classes/kohana/database/query/builder.php
  32. +4 −4 classes/kohana/database/query/builder/delete.php
  33. +8 −8 classes/kohana/database/query/builder/insert.php
  34. +8 −9 classes/kohana/database/query/builder/join.php
  35. +29 −33 classes/kohana/database/query/builder/select.php
  36. +7 −7 classes/kohana/database/query/builder/update.php
  37. +13 −13 classes/kohana/database/query/builder/where.php
  38. +14 −7 classes/kohana/database/result.php
  39. +1 −1 classes/kohana/database/result/cached.php
  40. +10 −11 classes/kohana/db.php
  41. +13 −8 classes/kohana/model/database.php
  42. +2 −2 classes/kohana/session/database.php
  43. +1 −1 classes/model/database.php
  44. +1 −1 classes/session/database.php
  45. +1 −1 config/database.php
  46. +1 −1 config/session.php
  47. +2 −2 config/userguide.php
  48. +2 −1 guide/database/config.md
  49. +2 −2 guide/database/examples.md
  50. +1 −1 guide/database/menu.md
  51. +1 −1 guide/database/query.md
  52. +1 −3 guide/database/query/builder.md
  53. +4 −4 guide/database/query/{prepared.md → parameterized.md}
  54. +1 −1 guide/database/results.md
View
4 classes/config/database.php
@@ -1,12 +1,12 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Transparent extension for the Kohana_Config_Database class
*
* @package Kohana/Database
* @category Configuration
* @author Kohana Team
- * @copyright (c) 2011 Kohana Team
+ * @copyright (c) 2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Config_Database extends Kohana_Config_Database {}
View
2 classes/config/database/reader.php
@@ -6,7 +6,7 @@
* @package Kohana/Database
* @category Configuration
* @author Kohana Team
- * @copyright (c) 2011 Kohana Team
+ * @copyright (c) 2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Config_Database_Reader extends Kohana_Config_Database_Reader
View
2 classes/config/database/writer.php
@@ -6,7 +6,7 @@
* @package Kohana/Database
* @category Configuration
* @author Kohana Team
- * @copyright (c) 2011 Kohana Team
+ * @copyright (c) 2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Config_Database_Writer extends Kohana_Config_Database_Writer
View
2 classes/database.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
abstract class Database extends Kohana_Database {}
View
2 classes/database/exception.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Exception extends Kohana_Database_Exception {}
View
2 classes/database/expression.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Expression extends Kohana_Database_Expression {}
View
2 classes/database/mysql.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_MySQL extends Kohana_Database_MySQL {}
View
2 classes/database/mysql/result.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_MySQL_Result extends Kohana_Database_MySQL_Result {}
View
2 classes/database/pdo.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_PDO extends Kohana_Database_PDO {}
View
2 classes/database/query.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Query extends Kohana_Database_Query {}
View
2 classes/database/query/builder.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
abstract class Database_Query_Builder extends Kohana_Database_Query_Builder {}
View
2 classes/database/query/builder/delete.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Query_Builder_Delete extends Kohana_Database_Query_Builder_Delete {}
View
2 classes/database/query/builder/insert.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Query_Builder_Insert extends Kohana_Database_Query_Builder_Insert {}
View
2 classes/database/query/builder/join.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Query_Builder_Join extends Kohana_Database_Query_Builder_Join {}
View
2 classes/database/query/builder/select.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Query_Builder_Select extends Kohana_Database_Query_Builder_Select {}
View
2 classes/database/query/builder/update.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Query_Builder_Update extends Kohana_Database_Query_Builder_Update {}
View
2 classes/database/query/builder/where.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
abstract class Database_Query_Builder_Where extends Kohana_Database_Query_Builder_Where {}
View
2 classes/database/result.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
abstract class Database_Result extends Kohana_Database_Result {}
View
2 classes/database/result/cached.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Database_Result_Cached extends Kohana_Database_Result_Cached {}
View
2 classes/db.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class DB extends Kohana_DB {}
View
6 classes/kohana/config/database.php
@@ -1,15 +1,15 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Backwards compatibility extension for the database writer.
*
* @package Kohana/Database
* @category Configuration
* @author Kohana Team
- * @copyright (c) 2011 Kohana Team
+ * @copyright (c) 2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Config_Database extends Kohana_Config_Database_Writer
{
-
+
}
View
17 classes/kohana/config/database/reader.php
@@ -6,12 +6,12 @@
* @package Kohana/Database
* @category Configuration
* @author Kohana Team
- * @copyright (c) 2011 Kohana Team
+ * @copyright (c) 2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Config_Database_Reader implements Kohana_Config_Reader
{
- protected $_db_instance = 'default';
+ protected $_db_instance;
protected $_table_name = 'config';
@@ -26,6 +26,10 @@ public function __construct(array $config = NULL)
{
$this->_db_instance = $config['instance'];
}
+ elseif ($this->_db_instance === NULL)
+ {
+ $this->_db_instance = Database::$default;
+ }
if (isset($config['table_name']))
{
@@ -43,6 +47,15 @@ public function __construct(array $config = NULL)
*/
public function load($group)
{
+ /**
+ * Prevents the catch-22 scenario where the database config reader attempts to load the
+ * database connections details from the database.
+ *
+ * @link http://dev.kohanaframework.org/issues/4316
+ */
+ if ($group === 'database')
+ return FALSE;
+
$query = DB::select('config_key', 'config_value')
->from($this->_table_name)
->where('group_name', '=', $group)
View
2 classes/kohana/config/database/writer.php
@@ -6,7 +6,7 @@
* @package Kohana
* @category Configuration
* @author Kohana Team
- * @copyright (c) 2007-2011 Kohana Team
+ * @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Config_Database_Writer extends Config_Database_Reader implements Kohana_Config_Writer
View
53 classes/kohana/database.php
@@ -1,9 +1,9 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database connection wrapper/helper.
*
* You may get a database instance using `Database::instance('name')` where
- * name is the [config](database/config) group.
+ * name is the [config](database/config) group.
*
* This class provides connection instance management via Database Drivers, as
* well as quoting, escaping and other related functions. Querys are done using
@@ -13,7 +13,7 @@
* @package Kohana/Database
* @category Base
* @author Kohana Team
- * @copyright (c) 2008-2010 Kohana Team
+ * @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaphp.com/license
*/
abstract class Kohana_Database {
@@ -45,8 +45,8 @@
* // Create a custom configured instance
* $db = Database::instance('custom', $config);
*
- * @param string instance name
- * @param array configuration parameters
+ * @param string $name instance name
+ * @param array $config configuration parameters
* @return Database
*/
public static function instance($name = NULL, array $config = NULL)
@@ -113,6 +113,11 @@ protected function __construct($name, array $config)
// Store the config locally
$this->_config = $config;
+ if (empty($this->_config['table_prefix']))
+ {
+ $this->_config['table_prefix'] = '';
+ }
+
// Store the database instance
Database::$instances[$name] = $this;
}
@@ -177,7 +182,7 @@ public function disconnect()
* $db->set_charset('utf8');
*
* @throws Database_Exception
- * @param string character set name
+ * @param string $charset character set name
* @return void
*/
abstract public function set_charset($charset);
@@ -191,10 +196,10 @@ public function disconnect()
* // Make a SELECT query and use "Model_User" for the results
* $db->query(Database::SELECT, 'SELECT * FROM users LIMIT 1', 'Model_User');
*
- * @param integer Database::SELECT, Database::INSERT, etc
- * @param string SQL query
- * @param mixed result object class string, TRUE for stdClass, FALSE for assoc array
- * @param array object construct parameters for result class
+ * @param integer $type Database::SELECT, Database::INSERT, etc
+ * @param string $sql SQL query
+ * @param mixed $as_object result object class string, TRUE for stdClass, FALSE for assoc array
+ * @param array $params object construct parameters for result class
* @return object Database_Result for SELECT queries
* @return array list (insert id, row count) for INSERT queries
* @return integer number of affected rows for all other queries
@@ -219,7 +224,7 @@ public function disconnect()
* $db->rollback();
* }
*
- * @param string transaction mode
+ * @param string $mode transaction mode
* @return boolean
*/
abstract public function begin($mode = NULL);
@@ -250,7 +255,7 @@ public function disconnect()
* // Get the total number of records in the "users" table
* $count = $db->count_records('users');
*
- * @param mixed table name string or array(query, alias)
+ * @param mixed $table table name string or array(query, alias)
* @return integer
*/
public function count_records($table)
@@ -267,7 +272,7 @@ public function count_records($table)
*
* $db->datatype('char');
*
- * @param string SQL data type
+ * @param string $type SQL data type
* @return array
*/
public function datatype($type)
@@ -342,7 +347,7 @@ public function datatype($type)
* // Get all user-related tables
* $tables = $db->list_tables('user%');
*
- * @param string table to search for
+ * @param string $like table to search for
* @return array
*/
abstract public function list_tables($like = NULL);
@@ -360,9 +365,9 @@ public function datatype($type)
* // Get the columns from a table that doesn't use the table prefix
* $columns = $db->list_columns('users', NULL, FALSE);
*
- * @param string table to get columns from
- * @param string column to search for
- * @param boolean whether to add the table prefix automatically or not
+ * @param string $table table to get columns from
+ * @param string $like column to search for
+ * @param boolean $add_prefix whether to add the table prefix automatically or not
* @return array
*/
abstract public function list_columns($table, $like = NULL, $add_prefix = TRUE);
@@ -373,7 +378,7 @@ public function datatype($type)
* // Returns: array('CHAR', '6')
* list($type, $length) = $db->_parse_type('CHAR(6)');
*
- * @param string
+ * @param string $type
* @return array list containing the type and length, if any
*/
protected function _parse_type($type)
@@ -385,7 +390,7 @@ protected function _parse_type($type)
}
// Closing parenthesis
- $close = strpos($type, ')', $open);
+ $close = strrpos($type, ')', $open);
// Length without parentheses
$length = substr($type, $open + 1, $close - 1 - $open);
@@ -420,7 +425,7 @@ public function table_prefix()
* [Database_Query] objects will be compiled and converted to a sub-query.
* All other objects will be converted using the `__toString` method.
*
- * @param mixed any value to quote
+ * @param mixed $value any value to quote
* @return string
* @uses Database::escape
*/
@@ -488,7 +493,7 @@ public function quote($value)
* [Database_Query] objects will be compiled and converted to a sub-query.
* All other objects will be converted using the `__toString` method.
*
- * @param mixed column name or array(column, alias)
+ * @param mixed $column column name or array(column, alias)
* @return string
* @uses Database::quote_identifier
* @uses Database::table_prefix
@@ -572,7 +577,7 @@ public function quote_column($column)
* [Database_Query] objects will be compiled and converted to a sub-query.
* All other objects will be converted using the `__toString` method.
*
- * @param mixed table name or array(table, alias)
+ * @param mixed $table table name or array(table, alias)
* @return string
* @uses Database::quote_identifier
* @uses Database::table_prefix
@@ -644,7 +649,7 @@ public function quote_table($table)
* [Database_Query] objects will be compiled and converted to a sub-query.
* All other objects will be converted using the `__toString` method.
*
- * @param mixed any identifier
+ * @param mixed $value any identifier
* @return string
*/
public function quote_identifier($value)
@@ -701,7 +706,7 @@ public function quote_identifier($value)
*
* $value = $db->escape('any string');
*
- * @param string value to quote
+ * @param string $value value to quote
* @return string
*/
abstract public function escape($value);
View
2 classes/kohana/database/exception.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database exceptions.
*
View
2 classes/kohana/database/expression.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database expressions can be used to add unescaped SQL fragments to a
* [Database_Query_Builder] object.
View
8 classes/kohana/database/mysql.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* MySQL database connection.
*
@@ -97,7 +97,7 @@ public function connect()
/**
* Select the database
*
- * @param string Database
+ * @param string $database Database
* @return void
*/
protected function _select_db($database)
@@ -276,7 +276,7 @@ public function datatype($type)
*
* @link http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
*
- * @param string Isolation level
+ * @param string $mode Isolation level
* @return boolean
*/
public function begin($mode = NULL)
@@ -297,7 +297,6 @@ public function begin($mode = NULL)
/**
* Commit a SQL transaction
*
- * @param string Isolation level
* @return boolean
*/
public function commit()
@@ -311,7 +310,6 @@ public function commit()
/**
* Rollback a SQL transaction
*
- * @param string Isolation level
* @return boolean
*/
public function rollback()
View
2 classes/kohana/database/mysql/result.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* MySQL database result. See [Results](/database/results) for usage and examples.
*
View
8 classes/kohana/database/pdo.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* PDO database connection.
*
@@ -41,18 +41,18 @@ public function connect()
unset($this->_config['connection']);
// Force PDO to use exceptions for all errors
- $attrs = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
+ $options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
if ( ! empty($persistent))
{
// Make the connection persistent
- $attrs[PDO::ATTR_PERSISTENT] = TRUE;
+ $options[PDO::ATTR_PERSISTENT] = TRUE;
}
try
{
// Create a new PDO connection
- $this->_connection = new PDO($dsn, $username, $password, $attrs);
+ $this->_connection = new PDO($dsn, $username, $password, $options);
}
catch (PDOException $e)
{
View
28 classes/kohana/database/query.php
@@ -1,6 +1,6 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
- * Database query wrapper. See [Prepared Statements](database/query/prepared) for usage and examples.
+ * Database query wrapper. See [Parameterized Statements](database/query/parameterized) for usage and examples.
*
* @package Kohana/Database
* @category Query
@@ -34,8 +34,8 @@ class Kohana_Database_Query {
/**
* Creates a new SQL query of the specified type.
*
- * @param integer query type: Database::SELECT, Database::INSERT, etc
- * @param string query string
+ * @param integer $type query type: Database::SELECT, Database::INSERT, etc
+ * @param string $sql query string
* @return void
*/
public function __construct($type, $sql)
@@ -75,7 +75,7 @@ public function type()
/**
* Enables the query to be cached for a specified amount of time.
*
- * @param integer number of seconds to cache, 0 deletes it from the cache
+ * @param integer $lifetime number of seconds to cache, 0 deletes it from the cache
* @param boolean whether or not to execute the query during a cache hit
* @return $this
* @uses Kohana::$cache_life
@@ -111,7 +111,8 @@ public function as_assoc()
/**
* Returns results as objects
*
- * @param string classname or TRUE for stdClass
+ * @param string $class classname or TRUE for stdClass
+ * @param array $params
* @return $this
*/
public function as_object($class = TRUE, array $params = NULL)
@@ -130,8 +131,8 @@ public function as_object($class = TRUE, array $params = NULL)
/**
* Set the value of a parameter in the query.
*
- * @param string parameter key to replace
- * @param mixed value to use
+ * @param string $param parameter key to replace
+ * @param mixed $value value to use
* @return $this
*/
public function param($param, $value)
@@ -145,8 +146,8 @@ public function param($param, $value)
/**
* Bind a variable to a parameter in the query.
*
- * @param string parameter key to replace
- * @param mixed variable to use
+ * @param string $param parameter key to replace
+ * @param mixed $var variable to use
* @return $this
*/
public function bind($param, & $var)
@@ -160,7 +161,7 @@ public function bind($param, & $var)
/**
* Add multiple parameters to the query.
*
- * @param array list of parameters
+ * @param array $params list of parameters
* @return $this
*/
public function parameters(array $params)
@@ -175,7 +176,7 @@ public function parameters(array $params)
* Compile the SQL query and return it. Replaces any parameters with their
* given values.
*
- * @param object Database instance
+ * @param object $db Database instance
* @return string
*/
public function compile(Database $db)
@@ -198,10 +199,9 @@ public function compile(Database $db)
/**
* Execute the current query on the given database.
*
- * @param mixed Database instance or name of instance
+ * @param mixed $db Database instance or name of instance
* @param string result object classname, TRUE for stdClass or FALSE for array
* @param array result object constructor arguments
- *
* @return object Database_Result for SELECT queries
* @return mixed the insert id for INSERT queries
* @return integer number of affected rows for all other queries
View
22 classes/kohana/database/query/builder.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database query builder. See [Query Builder](/database/query/builder) for usage and examples.
*
@@ -13,8 +13,8 @@
/**
* Compiles an array of JOIN statements into an SQL partial.
*
- * @param object Database instance
- * @param array join statements
+ * @param object $db Database instance
+ * @param array $joins join statements
* @return string
*/
protected function _compile_join(Database $db, array $joins)
@@ -34,8 +34,8 @@ protected function _compile_join(Database $db, array $joins)
* Compiles an array of conditions into an SQL partial. Used for WHERE
* and HAVING.
*
- * @param object Database instance
- * @param array condition statements
+ * @param object $db Database instance
+ * @param array $conditions condition statements
* @return string
*/
protected function _compile_conditions(Database $db, array $conditions)
@@ -144,8 +144,8 @@ protected function _compile_conditions(Database $db, array $conditions)
/**
* Compiles an array of set values into an SQL partial. Used for UPDATE.
*
- * @param object Database instance
- * @param array updated values
+ * @param object $db Database instance
+ * @param array $values updated values
* @return string
*/
protected function _compile_set(Database $db, array $values)
@@ -174,8 +174,8 @@ protected function _compile_set(Database $db, array $values)
/**
* Compiles an array of GROUP BY columns into an SQL partial.
*
- * @param object Database instance
- * @param array columns
+ * @param object $db Database instance
+ * @param array $columns
* @return string
*/
protected function _compile_group_by(Database $db, array $columns)
@@ -204,8 +204,8 @@ protected function _compile_group_by(Database $db, array $columns)
/**
* Compiles an array of ORDER BY statements into an SQL partial.
*
- * @param object Database instance
- * @param array sorting columns
+ * @param object $db Database instance
+ * @param array $columns sorting columns
* @return string
*/
protected function _compile_order_by(Database $db, array $columns)
View
8 classes/kohana/database/query/builder/delete.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database query builder for DELETE statements. See [Query Builder](/database/query/builder) for usage and examples.
*
@@ -16,7 +16,7 @@ class Kohana_Database_Query_Builder_Delete extends Database_Query_Builder_Where
/**
* Set the table for a delete.
*
- * @param mixed table name or array($table, $alias) or object
+ * @param mixed $table table name or array($table, $alias) or object
* @return void
*/
public function __construct($table = NULL)
@@ -34,7 +34,7 @@ public function __construct($table = NULL)
/**
* Sets the table to delete from.
*
- * @param mixed table name or array($table, $alias) or object
+ * @param mixed $table table name or array($table, $alias) or object
* @return $this
*/
public function table($table)
@@ -47,7 +47,7 @@ public function table($table)
/**
* Compile the SQL query and return it.
*
- * @param object Database instance
+ * @param object $db Database instance
* @return string
*/
public function compile(Database $db)
View
16 classes/kohana/database/query/builder/insert.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database query builder for INSERT statements. See [Query Builder](/database/query/builder) for usage and examples.
*
@@ -22,8 +22,8 @@ class Kohana_Database_Query_Builder_Insert extends Database_Query_Builder {
/**
* Set the table and columns for an insert.
*
- * @param mixed table name or array($table, $alias) or object
- * @param array column names
+ * @param mixed $table table name or array($table, $alias) or object
+ * @param array $columns column names
* @return void
*/
public function __construct($table = NULL, array $columns = NULL)
@@ -47,7 +47,7 @@ public function __construct($table = NULL, array $columns = NULL)
/**
* Sets the table to insert into.
*
- * @param mixed table name or array($table, $alias) or object
+ * @param mixed $table table name or array($table, $alias) or object
* @return $this
*/
public function table($table)
@@ -60,7 +60,7 @@ public function table($table)
/**
* Set the columns that will be inserted.
*
- * @param array column names
+ * @param array $columns column names
* @return $this
*/
public function columns(array $columns)
@@ -73,7 +73,7 @@ public function columns(array $columns)
/**
* Adds or overwrites values. Multiple value sets can be added.
*
- * @param array values list
+ * @param array $values values list
* @param ...
* @return $this
*/
@@ -95,7 +95,7 @@ public function values(array $values)
/**
* Use a sub-query to for the inserted values.
*
- * @param object Database_Query of SELECT type
+ * @param object $query Database_Query of SELECT type
* @return $this
*/
public function select(Database_Query $query)
@@ -113,7 +113,7 @@ public function select(Database_Query $query)
/**
* Compile the SQL query and return it.
*
- * @param object Database instance
+ * @param object $db Database instance
* @return string
*/
public function compile(Database $db)
View
17 classes/kohana/database/query/builder/join.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database query builder for JOIN statements. See [Query Builder](/database/query/builder) for usage and examples.
*
@@ -26,8 +26,8 @@ class Kohana_Database_Query_Builder_Join extends Database_Query_Builder {
* Creates a new JOIN statement for a table. Optionally, the type of JOIN
* can be specified as the second parameter.
*
- * @param mixed column name or array($column, $alias) or object
- * @param string type of JOIN: INNER, RIGHT, LEFT, etc
+ * @param mixed $table column name or array($column, $alias) or object
+ * @param string $type type of JOIN: INNER, RIGHT, LEFT, etc
* @return void
*/
public function __construct($table, $type = NULL)
@@ -45,9 +45,9 @@ public function __construct($table, $type = NULL)
/**
* Adds a new condition for joining.
*
- * @param mixed column name or array($column, $alias) or object
- * @param string logic operator
- * @param mixed column name or array($column, $alias) or object
+ * @param mixed $c1 column name or array($column, $alias) or object
+ * @param string $op logic operator
+ * @param mixed $c2 column name or array($column, $alias) or object
* @return $this
*/
public function on($c1, $op, $c2)
@@ -65,8 +65,7 @@ public function on($c1, $op, $c2)
/**
* Adds a new condition for joining.
*
- * @param string column name
- * @param ...
+ * @param string $columns column name
* @return $this
*/
public function using($columns)
@@ -86,7 +85,7 @@ public function using($columns)
/**
* Compile the SQL partial for a JOIN statement and return it.
*
- * @param object Database instance
+ * @param object $db Database instance
* @return string
*/
public function compile(Database $db)
View
62 classes/kohana/database/query/builder/select.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database query builder for SELECT statements. See [Query Builder](/database/query/builder) for usage and examples.
*
@@ -40,7 +40,7 @@ class Kohana_Database_Query_Builder_Select extends Database_Query_Builder_Where
/**
* Sets the initial columns to select from.
*
- * @param array column list
+ * @param array $columns column list
* @return void
*/
public function __construct(array $columns = NULL)
@@ -58,7 +58,7 @@ public function __construct(array $columns = NULL)
/**
* Enables or disables selecting only unique columns using "SELECT DISTINCT"
*
- * @param boolean enable or disable distinct columns
+ * @param boolean $value enable or disable distinct columns
* @return $this
*/
public function distinct($value)
@@ -71,8 +71,7 @@ public function distinct($value)
/**
* Choose the columns to select from.
*
- * @param mixed column name or array($column, $alias) or object
- * @param ...
+ * @param mixed $columns column name or array($column, $alias) or object
* @return $this
*/
public function select($columns = NULL)
@@ -87,7 +86,7 @@ public function select($columns = NULL)
/**
* Choose the columns to select from, using an array.
*
- * @param array list of column names or aliases
+ * @param array $columns list of column names or aliases
* @return $this
*/
public function select_array(array $columns)
@@ -100,8 +99,7 @@ public function select_array(array $columns)
/**
* Choose the tables to select "FROM ..."
*
- * @param mixed table name or array($table, $alias) or object
- * @param ...
+ * @param mixed $table table name or array($table, $alias) or object
* @return $this
*/
public function from($tables)
@@ -116,8 +114,8 @@ public function from($tables)
/**
* Adds addition tables to "JOIN ...".
*
- * @param mixed column name or array($column, $alias) or object
- * @param string join type (LEFT, RIGHT, INNER, etc)
+ * @param mixed $table column name or array($column, $alias) or object
+ * @param string $type join type (LEFT, RIGHT, INNER, etc)
* @return $this
*/
public function join($table, $type = NULL)
@@ -130,9 +128,9 @@ public function join($table, $type = NULL)
/**
* Adds "ON ..." conditions for the last created JOIN statement.
*
- * @param mixed column name or array($column, $alias) or object
- * @param string logic operator
- * @param mixed column name or array($column, $alias) or object
+ * @param mixed $c1 column name or array($column, $alias) or object
+ * @param string $op logic operator
+ * @param mixed $c2 column name or array($column, $alias) or object
* @return $this
*/
public function on($c1, $op, $c2)
@@ -145,8 +143,7 @@ public function on($c1, $op, $c2)
/**
* Adds "USING ..." conditions for the last created JOIN statement.
*
- * @param string column name
- * @param ...
+ * @param string $columns column name
* @return $this
*/
public function using($columns)
@@ -161,8 +158,7 @@ public function using($columns)
/**
* Creates a "GROUP BY ..." filter.
*
- * @param mixed column name or array($column, $alias) or object
- * @param ...
+ * @param mixed $columns column name or array($column, $alias) or object
* @return $this
*/
public function group_by($columns)
@@ -177,9 +173,9 @@ public function group_by($columns)
/**
* Alias of and_having()
*
- * @param mixed column name or array($column, $alias) or object
- * @param string logic operator
- * @param mixed column value
+ * @param mixed $column column name or array($column, $alias) or object
+ * @param string $op logic operator
+ * @param mixed $value column value
* @return $this
*/
public function having($column, $op, $value = NULL)
@@ -190,9 +186,9 @@ public function having($column, $op, $value = NULL)
/**
* Creates a new "AND HAVING" condition for the query.
*
- * @param mixed column name or array($column, $alias) or object
- * @param string logic operator
- * @param mixed column value
+ * @param mixed $column column name or array($column, $alias) or object
+ * @param string $op logic operator
+ * @param mixed $value column value
* @return $this
*/
public function and_having($column, $op, $value = NULL)
@@ -205,9 +201,9 @@ public function and_having($column, $op, $value = NULL)
/**
* Creates a new "OR HAVING" condition for the query.
*
- * @param mixed column name or array($column, $alias) or object
- * @param string logic operator
- * @param mixed column value
+ * @param mixed $column column name or array($column, $alias) or object
+ * @param string $op logic operator
+ * @param mixed $value column value
* @return $this
*/
public function or_having($column, $op, $value = NULL)
@@ -287,10 +283,10 @@ public function or_having_close()
/**
* Adds an other UNION clause.
- *
- * @param mixed $select if string, it must be the name of a table. Else
+ *
+ * @param mixed $select if string, it must be the name of a table. Else
* must be an instance of Database_Query_Builder_Select
- * @param boolean $all decides if it's an UNION or UNION ALL clause
+ * @param boolean $all decides if it's an UNION or UNION ALL clause
* @return $this
*/
public function union($select, $all = TRUE)
@@ -303,12 +299,12 @@ public function union($select, $all = TRUE)
throw new Kohana_Exception('first parameter must be a string or an instance of Database_Query_Builder_Select');
$this->_union []= array('select' => $select, 'all' => $all);
return $this;
- }
+ }
/**
* Start returning results after "OFFSET ..."
*
- * @param integer starting result number or NULL to reset
+ * @param integer $number starting result number or NULL to reset
* @return $this
*/
public function offset($number)
@@ -321,7 +317,7 @@ public function offset($number)
/**
* Compile the SQL query and return it.
*
- * @param object Database instance
+ * @param object $db Database instance
* @return string
*/
public function compile(Database $db)
@@ -399,7 +395,7 @@ public function compile(Database $db)
// Add offsets
$query .= ' OFFSET '.$this->_offset;
}
-
+
if ( ! empty($this->_union))
{
foreach ($this->_union as $u) {
View
14 classes/kohana/database/query/builder/update.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database query builder for UPDATE statements. See [Query Builder](/database/query/builder) for usage and examples.
*
@@ -19,7 +19,7 @@ class Kohana_Database_Query_Builder_Update extends Database_Query_Builder_Where
/**
* Set the table for a update.
*
- * @param mixed table name or array($table, $alias) or object
+ * @param mixed $table table name or array($table, $alias) or object
* @return void
*/
public function __construct($table = NULL)
@@ -37,7 +37,7 @@ public function __construct($table = NULL)
/**
* Sets the table to update.
*
- * @param mixed table name or array($table, $alias) or object
+ * @param mixed $table table name or array($table, $alias) or object
* @return $this
*/
public function table($table)
@@ -50,7 +50,7 @@ public function table($table)
/**
* Set the values to update with an associative array.
*
- * @param array associative (column => value) list
+ * @param array $pairs associative (column => value) list
* @return $this
*/
public function set(array $pairs)
@@ -66,8 +66,8 @@ public function set(array $pairs)
/**
* Set the value of a single column.
*
- * @param mixed table name or array($table, $alias) or object
- * @param mixed column value
+ * @param mixed $column table name or array($table, $alias) or object
+ * @param mixed $value column value
* @return $this
*/
public function value($column, $value)
@@ -80,7 +80,7 @@ public function value($column, $value)
/**
* Compile the SQL query and return it.
*
- * @param object Database instance
+ * @param object $db Database instance
* @return string
*/
public function compile(Database $db)
View
26 classes/kohana/database/query/builder/where.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database query builder for WHERE statements. See [Query Builder](/database/query/builder) for usage and examples.
*
@@ -22,9 +22,9 @@
/**
* Alias of and_where()
*
- * @param mixed column name or array($column, $alias) or object
- * @param string logic operator
- * @param mixed column value
+ * @param mixed $column column name or array($column, $alias) or object
+ * @param string $op logic operator
+ * @param mixed $value column value
* @return $this
*/
public function where($column, $op, $value)
@@ -35,9 +35,9 @@ public function where($column, $op, $value)
/**
* Creates a new "AND WHERE" condition for the query.
*
- * @param mixed column name or array($column, $alias) or object
- * @param string logic operator
- * @param mixed column value
+ * @param mixed $column column name or array($column, $alias) or object
+ * @param string $op logic operator
+ * @param mixed $value column value
* @return $this
*/
public function and_where($column, $op, $value)
@@ -50,9 +50,9 @@ public function and_where($column, $op, $value)
/**
* Creates a new "OR WHERE" condition for the query.
*
- * @param mixed column name or array($column, $alias) or object
- * @param string logic operator
- * @param mixed column value
+ * @param mixed $column column name or array($column, $alias) or object
+ * @param string $op logic operator
+ * @param mixed $value column value
* @return $this
*/
public function or_where($column, $op, $value)
@@ -133,8 +133,8 @@ public function or_where_close()
/**
* Applies sorting with "ORDER BY ..."
*
- * @param mixed column name or array($column, $alias) or object
- * @param string direction of sorting
+ * @param mixed $column column name or array($column, $alias) or object
+ * @param string $direction direction of sorting
* @return $this
*/
public function order_by($column, $direction = NULL)
@@ -147,7 +147,7 @@ public function order_by($column, $direction = NULL)
/**
* Return up to "LIMIT ..." results
*
- * @param integer maximum results to return or NULL to reset
+ * @param integer $number maximum results to return or NULL to reset
* @return $this
*/
public function limit($number)
View
21 classes/kohana/database/result.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database result wrapper. See [Results](/database/results) for usage and examples.
*
@@ -29,8 +29,10 @@
/**
* Sets the total number of rows and stores the result locally.
*
- * @param mixed query result
- * @param string SQL query
+ * @param mixed $result query result
+ * @param string $sql SQL query
+ * @param mixed $as_object
+ * @param array $params
* @return void
*/
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
@@ -89,8 +91,8 @@ public function cached()
* // Associative array of rows, "id" => "name"
* $rows = $result->as_array('id', 'name');
*
- * @param string column for associative keys
- * @param string column for values
+ * @param string $key column for associative keys
+ * @param string $value column for values
* @return array
*/
public function as_array($key = NULL, $value = NULL)
@@ -175,8 +177,8 @@ public function as_array($key = NULL, $value = NULL)
* // Get the "id" value
* $id = $result->get('id');
*
- * @param string column to get
- * @param mixed default value if the column does not exist
+ * @param string $name column to get
+ * @param mixed $default default value if the column does not exist
* @return mixed
*/
public function get($name, $default = NULL)
@@ -217,6 +219,7 @@ public function count()
* // Row 10 exists
* }
*
+ * @param int $offset
* @return boolean
*/
public function offsetExists($offset)
@@ -229,6 +232,7 @@ public function offsetExists($offset)
*
* $row = $result[10];
*
+ * @param int $offset
* @return mixed
*/
public function offsetGet($offset)
@@ -244,6 +248,8 @@ public function offsetGet($offset)
*
* [!!] You cannot modify a database result.
*
+ * @param int $offset
+ * @param mixed $value
* @return void
* @throws Kohana_Exception
*/
@@ -257,6 +263,7 @@ public function offsetGet($offset)
*
* [!!] You cannot modify a database result.
*
+ * @param int $offset
* @return void
* @throws Kohana_Exception
*/
View
2 classes/kohana/database/result/cached.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Object used for caching the results of select queries. See [Results](/database/results#select-cached) for usage and examples.
*
View
21 classes/kohana/db.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Provides a shortcut to get Database related objects for [making queries](../database/query).
*
@@ -35,8 +35,8 @@ class Kohana_DB {
* `Database::INSERT` queries will return the insert id and number of rows.
* For all other queries, the number of affected rows is returned.
*
- * @param integer type: Database::SELECT, Database::UPDATE, etc
- * @param string SQL statement
+ * @param integer $type type: Database::SELECT, Database::UPDATE, etc
+ * @param string $sql SQL statement
* @return Database_Query
*/
public static function query($type, $sql)
@@ -54,8 +54,7 @@ public static function query($type, $sql)
* // SELECT id AS user_id
* $query = DB::select(array('id', 'user_id'));
*
- * @param mixed column name or array($column, $alias) or object
- * @param ...
+ * @param mixed $columns column name or array($column, $alias) or object
* @return Database_Query_Builder_Select
*/
public static function select($columns = NULL)
@@ -69,7 +68,7 @@ public static function select($columns = NULL)
* // SELECT id, username
* $query = DB::select_array(array('id', 'username'));
*
- * @param array columns to select
+ * @param array $columns columns to select
* @return Database_Query_Builder_Select
*/
public static function select_array(array $columns = NULL)
@@ -83,8 +82,8 @@ public static function select_array(array $columns = NULL)
* // INSERT INTO users (id, username)
* $query = DB::insert('users', array('id', 'username'));
*
- * @param string table to insert into
- * @param array list of column names or array($column, $alias) or object
+ * @param string $table table to insert into
+ * @param array $columns list of column names or array($column, $alias) or object
* @return Database_Query_Builder_Insert
*/
public static function insert($table = NULL, array $columns = NULL)
@@ -98,7 +97,7 @@ public static function insert($table = NULL, array $columns = NULL)
* // UPDATE users
* $query = DB::update('users');
*
- * @param string table to update
+ * @param string $table table to update
* @return Database_Query_Builder_Update
*/
public static function update($table = NULL)
@@ -112,7 +111,7 @@ public static function update($table = NULL)
* // DELETE FROM users
* $query = DB::delete('users');
*
- * @param string table to delete from
+ * @param string $table table to delete from
* @return Database_Query_Builder_Delete
*/
public static function delete($table = NULL)
@@ -128,7 +127,7 @@ public static function delete($table = NULL)
* $query = DB::update('users')->set(array('login_count' => DB::expr('login_count + 1')))->where('id', '=', $id);
* $users = ORM::factory('user')->where(DB::expr("BINARY `hash`"), '=', $hash)->find();
*
- * @param string expression
+ * @param string $string expression
* @param array parameters
* @return Database_Expression
*/
View
21 classes/kohana/model/database.php
@@ -1,11 +1,11 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database Model base class.
*
* @package Kohana/Database
* @category Models
* @author Kohana Team
- * @copyright (c) 2008-2010 Kohana Team
+ * @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
abstract class Kohana_Model_Database extends Model {
@@ -17,8 +17,8 @@
*
* $model = Model::factory($name);
*
- * @param string model name
- * @param mixed Database instance object or string
+ * @param string $name model name
+ * @param mixed $db Database instance object or string
* @return Model
*/
public static function factory($name, $db = NULL)
@@ -30,23 +30,28 @@ public static function factory($name, $db = NULL)
}
// Database instance
- protected $_db = 'default';
+ protected $_db;
/**
* Loads the database.
*
* $model = new Foo_Model($db);
*
- * @param mixed Database instance object or string
+ * @param mixed $db Database instance object or string
* @return void
*/
public function __construct($db = NULL)
{
- if ($db !== NULL)
+ if ($db)
{
- // Set the database instance name
+ // Set the instance or name
$this->_db = $db;
}
+ elseif ( ! $this->_db)
+ {
+ // Use the default name
+ $this->_db = Database::$default;
+ }
if (is_string($this->_db))
{
View
4 classes/kohana/session/database.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Database-based session class.
*
@@ -47,7 +47,7 @@ public function __construct(array $config = NULL, $id = NULL)
if ( ! isset($config['group']))
{
// Use the default group
- $config['group'] = 'default';
+ $config['group'] = Database::$default;
}
// Load the database
View
2 classes/model/database.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
abstract class Model_Database extends Kohana_Model_Database {}
View
2 classes/session/database.php
@@ -1,3 +1,3 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
class Session_Database extends Kohana_Session_Database {}
View
2 config/database.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct access allowed.');
+<?php defined('SYSPATH') OR die('No direct access allowed.');
return array
(
View
2 config/session.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
return array(
'database' => array(
View
4 config/userguide.php
@@ -1,4 +1,4 @@
-<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') OR die('No direct script access.');
return array(
// Leave this alone
@@ -17,7 +17,7 @@
'description' => 'Database agnostic querying and result management.',
// Copyright message, shown in the footer for this module
- 'copyright' => '&copy; 2008–2010 Kohana Team',
+ 'copyright' => '&copy; 2008–2012 Kohana Team',
)
)
);
View
3 guide/database/config.md
@@ -24,7 +24,7 @@ CONNECTION_ARRAY
: Specific driver options for connecting to your database. (Driver options are explained [below](#connection-settings).)
TABLE_PREFIX
-: Prefix that will be added to all table names by the [query builder](#query_building). Prepared statements will **not** use the table prefix.
+: Prefix that will be added to all table names by the [query builder](#query_building).
QUERY_PROFILING
: Enables [profiling](../kohana/profiling) of database queries. This is useful for seeing how many queries each page is using, and which are taking the longest. You must enable the profiler the view these stats.
@@ -111,6 +111,7 @@ A [PDO database](http://php.net/manual/en/book.pdo.php) can accept these options
Type | Option | Description | Default value
----------|------------|----------------------------| -------------------------
`string` | dsn | PDO data source identifier | `localhost`
+`array` | options | Driver-specific options | none
`string` | username | Database username | `NULL`
`string` | password | Database password | `NULL`
`boolean` | persistent | Persistent connections | `FALSE`
View
4 guide/database/examples.md
@@ -2,9 +2,9 @@
Here are some "real world" examples of using the database library to construct your queries and use the results.
-## Examples of Prepared Statements
+## Examples of Parameterized Statements
-TODO: 4-6 examples of prepared statements of varying complexity, including a good bind() example.
+TODO: 4-6 examples of parameterized statements of varying complexity, including a good bind() example.
## Pagination and search/filter
View
2 guide/database/menu.md
@@ -1,7 +1,7 @@
## [Database]()
- [Configuration](config)
- [Querying](query)
- - [Prepared Statements](query/prepared)
+ - [Parameterized Statements](query/parameterized)
- [Query Builder](query/builder)
- [Results](results)
- [Examples](examples)
View
2 guide/database/query.md
@@ -1,5 +1,5 @@
# Making Queries
-There are two different ways to make queries. The simplest way to make a query is to use [Database_Query], via [DB::query], to manually create queries. These queries are called [prepared statements](query/prepared) and allow you to set query parameters which are automatically escaped. The second way to make a query is by building the query using method calls. This is done using the [query builder](query/builder).
+There are two different ways to make queries. The simplest way to make a query is to use [Database_Query], via [DB::query], to manually create queries. These queries are called [parameterized statements](query/parameterized) and allow you to set query parameters which are automatically escaped. The second way to make a query is by building the query using method calls. This is done using the [query builder](query/builder).
[!!] All queries are run using the `execute` method, which accepts a [Database] object or instance name. See [Database_Query::execute] for more information.
View
4 guide/database/query/builder.md
@@ -2,8 +2,6 @@
Creating queries dynamically using objects and methods allows queries to be written very quickly in an agnostic way. Query building also adds identifier (table and column name) quoting, as well as value quoting.
-[!!] At this time, it is not possible to combine query building with prepared statements.
-
## Select
Each type of database query is represented by a different class, each with their own methods. For instance, to create a SELECT query, we use [DB::select] which is a shortcut to return a new [Database_Query_Builder_Select] object:
@@ -38,7 +36,7 @@ By default, [DB::select] will select all columns (`SELECT * ...`), but you can a
Now take a minute to look at what this method chain is doing. First, we create a new selection object using the [DB::select] method. Next, we set table(s) using the `from()` method. Last, we search for a specific records using the `where()` method. We can display the SQL that will be executed by casting the query to a string:
- echo Kohana::debug((string) $query);
+ echo Debug::vars((string) $query);
// Should display:
// SELECT `username`, `password` FROM `users` WHERE `username` = 'john'
View
8 guide/database/query/prepared.md → guide/database/query/parameterized.md
@@ -1,6 +1,6 @@
-# Prepared Statements
+# Parameterized Statements
-Using prepared statements allows you to write SQL queries manually while still escaping the query values automatically to prevent [SQL injection](http://wikipedia.org/wiki/SQL_Injection). Creating a query is simple:
+Using parameterized statements allows you to write SQL queries manually while still escaping the query values automatically to prevent [SQL injection](http://wikipedia.org/wiki/SQL_Injection). Creating a query is simple:
$query = DB::query(Database::SELECT, 'SELECT * FROM users WHERE username = :user');
@@ -50,9 +50,9 @@ The only difference between `param()` and `bind()` is that `bind()` passes the v
## Display the raw query
-If you want to display the SQL that will be executed, simply cast the object to a string:
+If you want to display the SQL that will be executed, you can simply echo the query:
- echo Kohana::debug((string) $query);
+ echo $query;
// Should display:
// SELECT * FROM users WHERE username = 'john'
View
2 guide/database/results.md
@@ -2,7 +2,7 @@
## Execute
-Once you have a query object built, either through a prepared statement or through the builder, you must then `execute()` the query and retrieve the results. Depending on the query type used, the results returned will vary.
+Once you have a query object built, either through a parameterized statement or through the builder, you must then `execute()` the query and retrieve the results. Depending on the query type used, the results returned will vary.
## Select

0 comments on commit a11f464

Please sign in to comment.
Something went wrong with that request. Please try again.