Child classes:

OciAdapter
Adapter for OCI (not completed yet).
PgsqlAdapter
Adapter for Postgres (not completed yet)
MysqlAdapter
Adapter for MySQL.
SqliteAdapter
Adapter for SQLite.

Class Details

The base class for database connection adapters.

  • abstract:

Class Variables

public mixed $connection

The PDO connection object.

public static int $DEFAULT_PORT = 0

Default port.

public string $last_query

The last query run.

public static array $PDO_OPTIONS = array( PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false)

Default PDO options to set for each connection.

public string $protocol

The name of the protocol that is used.

public static string $QUOTE_CHARACTER = '`'

The quote character for stuff like column and field names.


Class Methods

protected Connection __construct ( array $info )

Class Connection is a singleton. Access it via instance().

  • array $info - Array containing URL parts
public boolean accepts_limit_and_order_for_update_and_delete ( )

Specifies whether or not adapter can use LIMIT/ORDER clauses with DELETE & UPDATE operations

  • return: (FALSE by default)
public array columns ( string $table )

Retrieves column meta data for the specified table.

  • string $table - Name of a table
  • return: An array of Column objects.
public void commit ( )

Commits the current transaction.

public string datetime_to_string ( DateTime $datetime )

Return a date time formatted into the database's datetime format.

  • DateTime $datetime - The DateTime object
public string date_to_string ( DateTime $datetime )

Return a date time formatted into the database's date format.

  • DateTime $datetime - The DateTime object
public string escape ( string $string )

Escapes quotes in a string.

  • string $string - The string to be quoted.
  • return: The string with any quotes in it properly escaped.
public string get_sequence_name ( string $table , string $column_name )

Return a default sequence name for the specified table.

  • string $table - Name of a table
  • string $column_name - Name of column sequence is for
  • return: sequence name or null if not supported.
public int insert_id ( [ string $sequence = null] )

Retrieve the insert id of the last model saved.

  • string $sequence - Optional name of a sequence to use
public static Connection instance ( [ string $connection_string_or_connection_name = null] )

Retrieve a database connection.

  • string $connection_string_or_connection_name - A database connection string (ex. mysql://user:[email protected][:port]/dbname) Everything after the protocol:// part is specific to the connection adapter. OR A connection name that is set in ActiveRecord\Config If null it will use the default connection specified by ActiveRecord\Config->set_default_connection
public string limit ( string $sql , int $offset , int $limit )

Adds a limit clause to the SQL query.

  • string $sql - The SQL statement.
  • int $offset - Row offset to start at.
  • int $limit - Maximum number of rows to return.
  • return: The SQL query that will limit results to specified parameters
  • abstract:
public void native_database_types ( )
  • abstract:
public string next_sequence_value ( string $sequence_name )

Return SQL for getting the next value in a sequence.

  • string $sequence_name - Name of the sequence
public static object the parse_connection_url ( string $connection_url )

Use this for any adapters that can take connection info in the form below to set the adapters connection info.

  • string $connection_url - A connection URL
  • return: parsed URL as an object.

 protocol://username:[email protected][:port]/dbname
 protocol://urlencoded%20username:urlencoded%[email protected][:port]/dbname?decode=true
 protocol://username:[email protected](/some/file/path)/dbname

	

Sqlite has a special syntax, as it does not need a database name or user authentication:

 sqlite://file.db
 sqlite://../relative/path/to/file.db
 sqlite://unix(/absolute/path/to/file.db)
 sqlite://windows(c%2A/absolute/path/to/file.db)

	

public mixed query ( string $sql , [ array &$values = array()] )

Execute a raw SQL query on the database.

  • string $sql - Raw SQL string to execute.
  • array &$values - Optional array of bind values
  • return: A result set object
public void query_and_fetch ( string $sql , $handler )

Execute a raw SQL query and fetch the results.

  • string $sql - Raw SQL string to execute.
  • Closure $handler - Closure that will be passed the fetched results.
public string query_and_fetch_one ( string $sql , [ array &$values = array()] )

Execute a query that returns maximum of one row with one field and return it.

  • string $sql - Raw SQL string to execute.
  • array &$values - Optional array of values to bind to the query.
public PDOStatement query_column_info ( string $table )

Query for column meta info and return statement handle.

  • string $table - Name of a table
  • abstract:
public PDOStatement query_for_tables ( )

Query for all tables in the current database. The result must only contain one column which has the name of the table.

  • abstract:
public string quote_name ( string $string )

Quote a name like table names and field names.

  • string $string - String to quote.
public void rollback ( )

Rollback a transaction.

public void set_encoding ( $charset )

Executes query to specify the character set for this connection.

  • $charset -
  • abstract:
public DateTime string_to_datetime ( string $string )

Converts a string representation of a datetime into a DateTime object.

  • string $string - A datetime in the form accepted by date_create()
public boolean supports_sequences ( )

Tells you if this adapter supports sequences or not.

public array tables ( )

Returns all tables for the current database.

  • return: Array containing table names.
public void transaction ( )

Starts a transaction.