Abstract Class ActiveRecord_Connection

Description

ActiveRecord_Connection extends PDO to provide some additional functionality required by ActiveRecord that may vary by database.

Per-database implementations may be provided by extending ActiveRecord_Connection or ActiveRecord_Connection_Default. Extensions are located by naming convention. A database-specific extension is expected to have the class name ActiveRecord_Connection_<Driver> where <Driver> is the name of the driver specified in the connection string with an initial capital letter (e.g. ActiveRecord_Connection_Oci for an OCI extension). If no database-specific extension is found, ActiveRecord_Connection_Default is used.

  • abstract:

Located in /activerecord/lib/ActiveRecord/Connection.php (line 37)

PDO
   |
   --ActiveRecord_Connection
Direct descendents
Class Description
 class ActiveRecord_Connection_Default Default implementation of ActiveRecord_Connection
Method Summary
 static void create (string $dsn, [string $username = NULL], [string $password = NULL], [array $options = NULL])
 ActiveRecord_Connection __construct (string $dsn, [string $username = NULL], [string $password = NULL], [array $options = NULL])
 string addLimit ( $sql, [int $limit = -1], [int $offset = 1])
 array columns (string $table)
 string defaultSequenceName (string $table, string $key)
 mixed nextSequenceValue (string $name)
 bool prefetchPrimaryKey (string $table)
 string sanitizeSQL (mixed $sql)
 array selectAll (string $sql, [int $mode = PDO::FETCH_BOTH])
 mixed selectValue (string $sql)
 array tables ()
Methods
static create (line 61)

Factory-type method for creating a new ActiveRecord_Connection (this must be used instead of constructing a new instance).

  • access: public
void create (string $dsn, [string $username = NULL], [string $password = NULL], [array $options = NULL])
  • string $dsn: The data source name
  • string $username: The user name for the DSN string (optional)
  • string $password: The password for the DSN string (optional)
  • array $options: An array of options as allowed by PDO (optional)
Constructor __construct (line 48)

Constructor

Do not call this method directly. Call create instead.

  • access: public
ActiveRecord_Connection __construct (string $dsn, [string $username = NULL], [string $password = NULL], [array $options = NULL])
  • string $dsn: The data source name
  • string $username: The user name for the DSN string (optional)
  • string $password: The password for the DSN string (optional)
  • array $options: An array of options as allowed by PDO (optional)

Redefinition of:
PDO::constructor __construct ( $dsn, $username, $passwd, [$options = ] )

Redefined in descendants as:
addLimit (line 110)

Append a LIMIT clause to a SQL statement

  • abstract:
  • access: public
string addLimit ( $sql, [int $limit = -1], [int $offset = 1])
  • int $limit: The maximum number of rows to return (or -1 for no maximum)
  • int $offset: The first row number to return in the results (e.g. 1 to return all rows, 2 to skip the first row)
  • $sql

Redefined in descendants as:
columns (line 120)

Return an array of ActiveRecordColumn objects for the named table.

  • abstract:
  • access: public
array columns (string $table)
  • string $table: The name of the table to return the columns for

Redefined in descendants as:
defaultSequenceName (line 135)

Return the sequence name that would be used to generated the

next value for the named key on the given table. Even if this connection does not support sequences or the resulting sequence does not exist, the name of what that sequence would be is returned.

  • abstract:
  • access: public
string defaultSequenceName (string $table, string $key)
  • string $table: The name of the table to generate the sequence name for
  • string $key: The name of the key on that table to generate the name for

Redefined in descendants as:
nextSequenceValue (line 167)

Returns the next value from the named sequence. This function throws ActiveRecord_SequencesNotSupportedError if the connection does not support sequences.

  • abstract:
  • access: public
mixed nextSequenceValue (string $name)
  • string $name: The name of the sequence

Redefined in descendants as:
prefetchPrimaryKey (line 156)

Used to test whether this connection uses sequences to generate

primary keys for the given table. If a new primary key value should be fetched prior to inserting a new record into the named table, true is returned. Otherwise false is returned, and the caller can assume it is safe to invoke lastInsertId following the execution of the insert statement.

  • abstract:
  • access: public
bool prefetchPrimaryKey (string $table)
  • string $table: The name of the table to test

Redefined in descendants as:
sanitizeSQL (line 100)

Accepts a string or array containing an SQL statement or

fragment an performs parameter substitution. When a string is provided, it is returned verbatim, however, when an array is provide, is is assumed that the first item in the array is the SQL statement (or fragment) containing parameter placeholders (in the form of question marks) and that all subsequent items in the array are ordered parameters to be used for substituion.

For example, passing in the following:

  1.    sanitizeSQL(array("status=? AND last_name LIKE ?"'Active''%Smith%'))
Would return this string:
  1.    "status='Active' AND last_name LIKE '%Smith%'"

Of course, this is actually more useful when passing in variables with unknown values as the parameters instead of literals, since sanitizeSQL handles any necessary escaping of the values.

  • abstract:
  • access: public
string sanitizeSQL (mixed $sql)
  • mixed $sql: The string or array to sanitize

Redefined in descendants as:
selectAll (line 202)

Runs the select query provided in the $sql parameter, then fetches all rows into an array. Each individual row is fetched using the mode parameter provided.

For example, if you have a table named users containing the following:

  1.    +----+------------+-----------+------------------+
  2.    | id first_name last_name email            |
  3.    +----+------------+-----------+------------------+
  4.    |  John       Doe       jdoe@google.com  |
  5.    |  John       Smith     jsmith@yahoo.com |
  6.    +----+------------+-----------+------------------+
and you run the following:
  1.    $connection->selectAll("SELECT * FROM users"PDO::FETCH_ASSOC);
It will return a data structure like this:
  1.    array(
  2.      array('id'=>1'first_name'=>'John''last_name'=>'Doe',   'email'=>'jdoe@google.com'),
  3.      array('id'=>2'first_name'=>'John''last_name'=>'Smith''email'=>'jsmith@yahoo.com')
  4.    )

Empty data sets return an empty array.

  • access: public
array selectAll (string $sql, [int $mode = PDO::FETCH_BOTH])
  • string $sql: The select statement to run
  • int $mode: The mode to use for fetching rows
selectValue (line 221)

This is a convenience method for running select queries which

return a single row containing only a single column. This method runs the provided query and returns the value from the first column of the first row of the results. Any other values in the result set are discarded. Empty result sets return NULL.

  • access: public
mixed selectValue (string $sql)
  • string $sql: The select statement to run
tables (line 142)

Returns an array of table names in the database

  • abstract:
  • access: public
array tables ()

Redefined in descendants as:

Inherited Methods

Inherited From PDO (Internal Class)

 constructor __construct ( $dsn, $username, $passwd, [$options = ] )
 beginTransaction ( )
 commit ( )
 errorCode ( )
 errorInfo ( )
 exec ( $query )
 getAttribute ( $attribute )
 getAvailableDrivers ( )
 inTransaction ( )
 lastInsertId ( [$seqname = ] )
 prepare ( $statment, [$options = ] )
 query ( )
 quote ( $string, [$paramtype = ] )
 rollBack ( )
 setAttribute ( $attribute, $value )
 __sleep ( )
 __wakeup ( )
Class Constants

Inherited Constants

Inherited from PDO (Internal Class)

ATTR_AUTOCOMMIT = 0
ATTR_CASE = 8
ATTR_CLIENT_VERSION = 5
ATTR_CONNECTION_STATUS = 7
ATTR_CURSOR = 10
ATTR_CURSOR_NAME = 9
ATTR_DEFAULT_FETCH_MODE = 19
ATTR_DRIVER_NAME = 16
ATTR_EMULATE_PREPARES = 20
ATTR_ERRMODE = 3
ATTR_FETCH_CATALOG_NAMES = 15
ATTR_FETCH_TABLE_NAMES = 14
ATTR_MAX_COLUMN_LEN = 18
ATTR_ORACLE_NULLS = 11
ATTR_PERSISTENT = 12
ATTR_PREFETCH = 1
ATTR_SERVER_INFO = 6
ATTR_SERVER_VERSION = 4
ATTR_STATEMENT_CLASS = 13
ATTR_STRINGIFY_FETCHES = 17
ATTR_TIMEOUT = 2
CASE_LOWER = 2
CASE_NATURAL = 0
CASE_UPPER = 1
CURSOR_FWDONLY = 0
CURSOR_SCROLL = 1
ERRMODE_EXCEPTION = 2
ERRMODE_SILENT = 0
ERRMODE_WARNING = 1
ERR_NONE = '00000'
FETCH_ASSOC = 2
FETCH_BOTH = 4
FETCH_BOUND = 6
FETCH_CLASS = 8
FETCH_CLASSTYPE = 262144
FETCH_COLUMN = 7
FETCH_FUNC = 10
FETCH_GROUP = 65536
FETCH_INTO = 9
FETCH_KEY_PAIR = 12
FETCH_LAZY = 1
FETCH_NAMED = 11
FETCH_NUM = 3
FETCH_OBJ = 5
FETCH_ORI_ABS = 4
FETCH_ORI_FIRST = 2
FETCH_ORI_LAST = 3
FETCH_ORI_NEXT = 0
FETCH_ORI_PRIOR = 1
FETCH_ORI_REL = 5
FETCH_PROPS_LATE = 1048576
FETCH_SERIALIZE = 524288
FETCH_UNIQUE = 196608
MYSQL_ATTR_DIRECT_QUERY = 1003
MYSQL_ATTR_FOUND_ROWS = 1004
MYSQL_ATTR_IGNORE_SPACE = 1005
MYSQL_ATTR_INIT_COMMAND = 1002
MYSQL_ATTR_LOCAL_INFILE = 1001
MYSQL_ATTR_SSL_CA = 1008
MYSQL_ATTR_SSL_CAPATH = 1009
MYSQL_ATTR_SSL_CERT = 1007
MYSQL_ATTR_SSL_CIPHER = 1010
MYSQL_ATTR_SSL_KEY = 1006
MYSQL_ATTR_USE_BUFFERED_QUERY = 1000
NULL_EMPTY_STRING = 1
NULL_NATURAL = 0
NULL_TO_STRING = 2
PARAM_BOOL = 5
PARAM_EVT_ALLOC = 0
PARAM_EVT_EXEC_POST = 3
PARAM_EVT_EXEC_PRE = 2
PARAM_EVT_FETCH_POST = 5
PARAM_EVT_FETCH_PRE = 4
PARAM_EVT_FREE = 1
PARAM_EVT_NORMALIZE = 6
PARAM_INPUT_OUTPUT = 2147483648
PARAM_INT = 1
PARAM_LOB = 3
PARAM_NULL = 0
PARAM_STMT = 4
PARAM_STR = 2

Documentation generated on Wed, 25 Apr 2012 09:46:42 -0700 by phpDocumentor 1.4.3