PHP Класс ORM, idiorm

http://github.com/j4mie/idiorm/ A single-class super-simple database abstraction layer for PHP. Provides (nearly) zero-configuration object-relational mapping and a fluent interface for building basic, commonly-used queries. BSD Licensed. Copyright (c) 2010, Jamie Matthews All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_config Map of configuration settings
$_connection_name Key name of the connections in self::$_db used by this instance
$_data The data for a hydrated instance of the class
$_db Map of database connections, instances of the PDO class
$_default_config Class configuration
$_dirty_fields lifetime of the object
$_distinct Should the query include a DISTINCT keyword?
$_expr_fields Fields that are to be inserted in the DB raw
$_group_by GROUP BY
$_having_conditions HAVING
$_instance_id_column this instance only. Overrides the config settings.
$_is_new Is this a new object (has create() been called)?
$_is_raw_query Is this a raw query?
$_join_sources Join sources
$_last_query Last query run, only populated if logging is enabled
$_last_statement Reference to previously used PDOStatement object to enable low-level access, if needed
$_limit LIMIT
$_offset OFFSET
$_order_by ORDER BY
$_query_cache Query cache, only used if query caching is enabled
$_query_log Log of all queries run, mapped by connection key, only populated if logging is enabled
$_raw_parameters The raw query parameters
$_raw_query The raw query
$_result_columns Columns to select in the result
$_table_alias Alias for the table to be used in SELECT queries
$_table_name The name of the table the current ORM instance is associated with
$_using_default_result_columns Are we using the default result column or have these been manually changed?
$_values Values to be bound to the query
$_where_conditions Array of WHERE clauses

Открытые методы

Метод Описание
__call ( string $name, array $arguments ) : ORM Magic method to capture calls to undefined class methods.
__callStatic ( string $name, array $arguments ) : ORM Magic method to capture calls to undefined static class methods.
__get ( $key ) --------------------- //
__isset ( $key )
__set ( $key, $value )
__unset ( $key )
_add_having_no_value ( $column_name, $operator ) Internal method to add a HAVING clause with no parameters(like IS NULL and IS NOT NULL)
_add_having_placeholder ( $column_name, $separator, $values ) Internal method to add a HAVING clause with multiple values (like IN and NOT IN)
_add_id_column_conditions ( &$query ) Add a WHERE clause for every column that belongs to the primary key
_add_where_no_value ( $column_name, $operator ) Add a WHERE clause with no parameters(like IS NULL and IS NOT NULL)
_add_where_placeholder ( $column_name, $separator, $values ) Add a WHERE clause with multiple values (like IN and NOT IN)
_setup_limit_clause_style ( string $connection_name ) Detect and initialise the limit clause style ("SELECT TOP 5" / ".
as_array ( ) Return the raw data wrapped by this ORM instance as an associative array. Column names may optionally be supplied as arguments, if so, only those keys will be returned.
avg ( $column ) Tell the ORM that you wish to execute a AVG query.
clear_cache ( $table_name = null, $connection_name = self::DEFAULT_CONNECTION ) Clear the query cache
configure ( string $key, mixed $value = null, string $connection_name = self::DEFAULT_CONNECTION ) Pass configuration settings to the class in the form of key/value pairs. As a shortcut, if the second argument is omitted and the key is a string, the setting is assumed to be the DSN string used by PDO to connect to the database (often, this will be the only configuration required to use Idiorm). If you have more than one setting you wish to configure, another shortcut is to pass an array of settings (and omit the second argument).
count ( $column = '*' ) Tell the ORM that you wish to execute a COUNT query.
count_null_id_columns ( ) Counts the number of columns that belong to the primary key and their value is null.
create ( $data = null ) Create a new, empty instance of the class. Used to add a new row to your database. May optionally be passed an associative array of data to populate the instance. If so, all fields will be flagged as dirty so all will be saved to the database when save() is called.
delete ( ) Delete this record from the database
delete_many ( ) Delete many records from the database
distinct ( ) Add a DISTINCT keyword before the list of columns in the SELECT query
find_array ( ) : array Tell the ORM that you are expecting multiple results from your query, and execute it. Will return an array, or an empty array if no rows were returned.
find_many ( ) : array | IdiormResultSet Tell the ORM that you are expecting multiple results from your query, and execute it. Will return an array of instances of the ORM class, or an empty array if no rows were returned.
find_one ( $id = null ) Tell the ORM that you are expecting a single result back from your query, and execute it. Will return a single instance of the ORM class, or false if no rows were returned.
find_result_set ( ) : IdiormResultSet Tell the ORM that you are expecting multiple results from your query, and execute it. Will return a result set object containing instances of the ORM class.
for_table ( string $table_name, string $connection_name = self::DEFAULT_CONNECTION ) : ORM Despite its slightly odd name, this is actually the factory method used to acquire instances of the class. It is named this way for the sake of a readable interface, ie ORM::for_table('table_name')->find_one()-> etc. As such, this will normally be the first method called in a chain.
force_all_dirty ( ) Force the ORM to flag all the fields in the $data array as "dirty" and therefore update them when save() is called.
full_outer_join ( $table, $constraint, $table_alias = null ) Add an FULL OUTER JOIN souce to the query
get ( $key ) Return the value of a property of this object (database row) or null if not present.
get_config ( string $key = null, string $connection_name = self::DEFAULT_CONNECTION ) Retrieve configuration options by key, or as whole array.
get_connection_names ( ) : array Get a list of the available connection names
get_db ( string $connection_name = self::DEFAULT_CONNECTION ) : PDO Returns the PDO instance used by the the ORM to communicate with the database. This can be called if any low-level DB access is required outside the class. If multiple connections are used, accepts an optional key name for the connection.
get_last_query ( null | string $connection_name = null ) : string Get the last query executed. Only works if the 'logging' config option is set to true. Otherwise this will return null. Returns last query from all connections if no connection_name is specified
get_last_statement ( ) : PDOStatement Returns the PDOStatement instance last used by any connection wrapped by the ORM.
get_query_log ( string $connection_name = self::DEFAULT_CONNECTION ) Get an array containing all the queries run on a specified connection up to now.
group_by ( $column_name ) Add a column to the list of columns to GROUP BY
group_by_expr ( $expr ) Add an unquoted expression to the list of columns to GROUP BY
having ( $column_name, $value = null ) Add a HAVING column = value clause to your query. Each time this is called in the chain, an additional HAVING will be added, and these will be ANDed together when the final query is built.
having_equal ( $column_name, $value = null ) More explicitly named version of for the having() method.
having_gt ( $column_name, $value = null ) Add a HAVING .
having_gte ( $column_name, $value = null ) Add a HAVING .
having_id_is ( $id ) Special method to query the table by its primary key.
having_in ( $column_name, $values = null ) Add a HAVING .
having_like ( $column_name, $value = null ) Add a HAVING .
having_lt ( $column_name, $value = null ) Add a HAVING .
having_lte ( $column_name, $value = null ) Add a HAVING .
having_not_equal ( $column_name, $value = null ) Add a HAVING column != value clause to your query.
having_not_in ( $column_name, $values = null ) Add a HAVING .
having_not_like ( $column_name, $value = null ) Add where HAVING .
having_not_null ( $column_name ) Add a HAVING column IS NOT NULL clause to your query
having_null ( $column_name ) Add a HAVING column IS NULL clause to your query
having_raw ( $clause, $parameters = [] ) Add a raw HAVING clause to the query. The clause should contain question mark placeholders, which will be bound to the parameters supplied in the second argument.
hydrate ( $data = [] ) This method can be called to hydrate (populate) this instance of the class from an associative array of data.
id ( $disallow_null = false ) Get the primary key ID of this object.
inner_join ( $table, $constraint, $table_alias = null ) Add an INNER JOIN souce to the query
is_dirty ( $key ) Check whether the given field has been changed since this object was saved.
is_new ( ) : boolean Check whether the model was the result of a call to create() or not
join ( $table, $constraint, $table_alias = null ) Add a simple JOIN source to the query
left_outer_join ( $table, $constraint, $table_alias = null ) Add a LEFT OUTER JOIN souce to the query
limit ( $limit ) Add a LIMIT to the query
max ( $column ) Tell the ORM that you wish to execute a MAX query.
min ( $column ) Tell the ORM that you wish to execute a MIN query.
offset ( $offset ) Add an OFFSET to the query
offsetExists ( $key ) --------------------- //
offsetGet ( $key )
offsetSet ( $key, $value )
offsetUnset ( $key )
order_by_asc ( $column_name ) Add an ORDER BY column ASC clause
order_by_desc ( $column_name ) Add an ORDER BY column DESC clause
order_by_expr ( $clause ) Add an unquoted expression as an ORDER BY clause
raw_execute ( string $query, array $parameters = [], string $connection_name = self::DEFAULT_CONNECTION ) : boolean Executes a raw query as a wrapper for PDOStatement::execute.
raw_join ( $table, $constraint, $table_alias, $parameters = [] ) Add a RAW JOIN source to the query
raw_query ( $query, $parameters = [] ) Perform a raw query. The query can contain placeholders in either named or question mark style. If placeholders are used, the parameters should be an array of values which will be bound to the placeholders in the query. If this method is called, all other query building methods will be ignored.
reset_config ( ) Delete all configs in _config array.
reset_db ( ) Delete all registered PDO objects in _db array.
right_outer_join ( $table, $constraint, $table_alias = null ) Add an RIGHT OUTER JOIN souce to the query
save ( ) Save any fields which have been modified on this object to the database.
select ( $column, $alias = null ) Add a column to the list of columns returned by the SELECT query. This defaults to '*'. The second optional argument is the alias to return the column as.
select_expr ( $expr, $alias = null ) Add an unquoted expression to the list of columns returned by the SELECT query. The second optional argument is the alias to return the column as.
select_many ( ) : ORM Add columns to the list of columns returned by the SELECT query. This defaults to '*'. Many columns can be supplied as either an array or as a list of parameters to the method.
select_many_expr ( ) : ORM Add an unquoted expression to the list of columns returned by the SELECT query. Many columns can be supplied as either an array or as a list of parameters to the method.
set ( $key, $value = null ) Set a property to a particular value on this object.
set_db ( PDO $db, string $connection_name = self::DEFAULT_CONNECTION ) Set the PDO object used by Idiorm to communicate with the database.
set_expr ( string | array $key, string | null $value = null ) Set a property to a particular value on this object.
sum ( $column ) Tell the ORM that you wish to execute a SUM query.
table_alias ( $alias ) Add an alias for the main table to be used in SELECT queries
use_id_column ( $id_column ) Specify the ID column to use for this instance or array of instances only.
where ( $column_name, $value = null ) Add a WHERE column = value clause to your query. Each time this is called in the chain, an additional WHERE will be added, and these will be ANDed together when the final query is built.
where_any_is ( $values, $operator = '=' ) Allows adding a WHERE clause that matches any of the conditions specified in the array. Each element in the associative array will be a different condition, where the key will be the column name.
where_equal ( $column_name, $value = null ) More explicitly named version of for the where() method.
where_gt ( $column_name, $value = null ) Add a WHERE .
where_gte ( $column_name, $value = null ) Add a WHERE .
where_id_in ( $ids ) Similar to where_id_is() but allowing multiple primary keys.
where_id_is ( $id ) Special method to query the table by its primary key
where_in ( $column_name, $values ) Add a WHERE .
where_like ( $column_name, $value = null ) Add a WHERE .
where_lt ( $column_name, $value = null ) Add a WHERE .
where_lte ( $column_name, $value = null ) Add a WHERE .
where_not_equal ( $column_name, $value = null ) Add a WHERE column != value clause to your query.
where_not_in ( $column_name, $values ) Add a WHERE .
where_not_like ( $column_name, $value = null ) Add where WHERE .
where_not_null ( $column_name ) Add a WHERE column IS NOT NULL clause to your query
where_null ( $column_name ) Add a WHERE column IS NULL clause to your query
where_raw ( $clause, $parameters = [] ) Add a raw WHERE clause to the query. The clause should contain question mark placeholders, which will be bound to the parameters supplied in the second argument.

Защищенные методы

Метод Описание
__construct ( $table_name, $data = [], $connection_name = self::DEFAULT_CONNECTION ) "Private" constructor; shouldn't be called directly.
_add_condition ( $type, $fragment, $values = [] ) Internal method to add a HAVING or WHERE condition to the query
_add_having ( $fragment, $values = [] ) Internal method to add a HAVING condition to the query
_add_join_source ( $join_operator, $table, $constraint, $table_alias = null ) Internal method to add a JOIN source to the query.
_add_order_by ( $column_name, $ordering ) Add an ORDER BY clause to the query
_add_result_column ( $expr, $alias = null ) Internal method to add an unquoted expression to the set of columns returned by the SELECT query. The second optional argument is the alias to return the expression as.
_add_simple_condition ( $type, $column_name, $separator, $value ) Helper method to compile a simple COLUMN SEPARATOR VALUE style HAVING or WHERE condition into a string and value ready to be passed to the _add_condition method. Avoids duplication of the call to _quote_identifier
_add_simple_having ( $column_name, $separator, $value ) Internal method to add a HAVING condition to the query
_add_simple_where ( $column_name, $separator, $value ) Internal method to add a WHERE condition to the query
_add_where ( $fragment, $values = [] ) Internal method to add a WHERE condition to the query
_build_conditions ( string $type ) : string Build a WHERE or HAVING clause
_build_group_by ( ) Build GROUP BY
_build_having ( ) Build the HAVING clause(s)
_build_insert ( ) Build an INSERT query
_build_join ( ) Build the JOIN sources
_build_limit ( ) Build LIMIT
_build_offset ( ) Build OFFSET
_build_order_by ( ) Build ORDER BY
_build_select ( ) Build a SELECT statement based on the clauses that have been passed to this instance by chaining method calls.
_build_select_start ( ) Build the start of the SELECT statement
_build_update ( ) Build an UPDATE query
_build_where ( ) Build the WHERE clause(s)
_cache_query_result ( $cache_key, $value, $table_name = null, $connection_name = self::DEFAULT_CONNECTION ) Add the given value to the query cache.
_call_aggregate_db_function ( string $sql_function, string $column ) : integer Execute an aggregate query on the current connection.
_check_query_cache ( $cache_key, $table_name = null, $connection_name = self::DEFAULT_CONNECTION ) Check the query cache for the given cache key. If a value is cached for the key, return the value. Otherwise, return false.
_create_cache_key ( $query, $parameters, $table_name = null, $connection_name = self::DEFAULT_CONNECTION ) Create a cache key for the given query and parameters.
_create_instance_from_row ( $row ) Create an ORM instance from the given row (an associative array of data fetched from the database)
_create_placeholders ( $fields ) Return a string containing the given number of question marks, separated by commas. Eg "?, ?, ?"
_detect_identifier_quote_character ( string $connection_name ) : string Return the correct character used to quote identifiers (table names, column names etc) by looking at the driver being used by PDO.
_detect_limit_clause_style ( string $connection_name ) : string Returns a constant after determining the appropriate limit clause style
_execute ( string $query, array $parameters = [], string $connection_name = self::DEFAULT_CONNECTION ) : boolean Internal helper method for executing statments. Logs queries, and stores statement object in ::_last_statment, accessible publicly through ::get_last_statement()
_find_many ( ) : array Tell the ORM that you are expecting multiple results from your query, and execute it. Will return an array of instances of the ORM class, or an empty array if no rows were returned.
_get_compound_id_column_values ( $value ) Helper method that filters a column/value array returning only those columns that belong to a compound primary key.
_get_compound_id_column_values_array ( $values ) Helper method that filters an array containing compound column/value arrays.
_get_id_column_name ( ) Return the name of the column in the database table which contains the primary key ID of the row.
_join_if_not_empty ( $glue, $pieces ) Wrapper around PHP's join function which only adds the pieces if they are not empty.
_log_query ( string $query, array $parameters, string $connection_name, float $query_time ) : boolean Add a query to the internal query log. Only works if the 'logging' config option is set to true.
_normalise_select_many_columns ( array $columns ) : array Take a column specification for the select many methods and convert it into a normalised array of columns and aliases.
_quote_identifier ( $identifier ) Quote a string that is used as an identifier (table names, column names etc) or an array containing multiple identifiers. This method can also deal with dot-separated identifiers eg table.column
_quote_identifier_part ( $part ) This method performs the actual quoting of a single part of an identifier, using the identifier quote character specified in the config (or autodetected).
_quote_one_identifier ( $identifier ) Quote a string that is used as an identifier (table names, column names etc). This method can also deal with dot-separated identifiers eg table.column
_run ( ) Execute the SELECT query that has been built up by chaining methods on this class. Return an array of rows as associative arrays.
_set_orm_property ( string | array $key, string | null $value = null, $expr = false ) Set a property on the ORM object.
_setup_db ( string $connection_name = self::DEFAULT_CONNECTION ) Set up the database connection used by the class
_setup_db_config ( string $connection_name ) Ensures configuration (multiple connections) is at least set to default.
_setup_identifier_quote_character ( string $connection_name ) Detect and initialise the character used to quote identifiers (table names, column names etc). If this has been specified manually using ORM::configure('identifier_quote_character', 'some-char'), this will do nothing.

Описание методов

__call() публичный Метод

In this case we are attempting to convert camel case formatted methods into underscore formatted methods. This allows us to call ORM methods using camel case and remain backwards compatible.
public __call ( string $name, array $arguments ) : ORM
$name string
$arguments array
Результат ORM

__callStatic() публичный статический Метод

In this case we are attempting to convert camel case formatted methods into underscore formatted methods. This allows us to call ORM methods using camel case and remain backwards compatible.
public static __callStatic ( string $name, array $arguments ) : ORM
$name string
$arguments array
Результат ORM

__construct() защищенный Метод

Use the ORM::for_table factory method instead.
protected __construct ( $table_name, $data = [], $connection_name = self::DEFAULT_CONNECTION )

__get() публичный Метод

--------------------- //
public __get ( $key )

__isset() публичный Метод

public __isset ( $key )

__set() публичный Метод

public __set ( $key, $value )

__unset() публичный Метод

public __unset ( $key )

_add_condition() защищенный Метод

Internal method to add a HAVING or WHERE condition to the query
protected _add_condition ( $type, $fragment, $values = [] )

_add_having() защищенный Метод

Internal method to add a HAVING condition to the query
protected _add_having ( $fragment, $values = [] )

_add_having_no_value() публичный Метод

Internal method to add a HAVING clause with no parameters(like IS NULL and IS NOT NULL)
public _add_having_no_value ( $column_name, $operator )

_add_having_placeholder() публичный Метод

Internal method to add a HAVING clause with multiple values (like IN and NOT IN)
public _add_having_placeholder ( $column_name, $separator, $values )

_add_id_column_conditions() публичный Метод

Add a WHERE clause for every column that belongs to the primary key
public _add_id_column_conditions ( &$query )

_add_join_source() защищенный Метод

The join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN. The table should be the name of the table to join to. The constraint may be either a string or an array with three elements. If it is a string, it will be compiled into the query as-is, with no escaping. The recommended way to supply the constraint is as an array with three elements: first_column, operator, second_column Example: array('user.id', '=', 'profile.user_id') will compile to ON user.id = profile.user_id The final (optional) argument specifies an alias for the joined table.
protected _add_join_source ( $join_operator, $table, $constraint, $table_alias = null )

_add_order_by() защищенный Метод

Add an ORDER BY clause to the query
protected _add_order_by ( $column_name, $ordering )

_add_result_column() защищенный Метод

Internal method to add an unquoted expression to the set of columns returned by the SELECT query. The second optional argument is the alias to return the expression as.
protected _add_result_column ( $expr, $alias = null )

_add_simple_condition() защищенный Метод

If column_name is an associative array, it will add a condition for each column
protected _add_simple_condition ( $type, $column_name, $separator, $value )

_add_simple_having() защищенный Метод

Internal method to add a HAVING condition to the query
protected _add_simple_having ( $column_name, $separator, $value )

_add_simple_where() защищенный Метод

Internal method to add a WHERE condition to the query
protected _add_simple_where ( $column_name, $separator, $value )

_add_where() защищенный Метод

Internal method to add a WHERE condition to the query
protected _add_where ( $fragment, $values = [] )

_add_where_no_value() публичный Метод

Add a WHERE clause with no parameters(like IS NULL and IS NOT NULL)
public _add_where_no_value ( $column_name, $operator )

_add_where_placeholder() публичный Метод

Add a WHERE clause with multiple values (like IN and NOT IN)
public _add_where_placeholder ( $column_name, $separator, $values )

_build_conditions() защищенный Метод

Build a WHERE or HAVING clause
protected _build_conditions ( string $type ) : string
$type string
Результат string

_build_group_by() защищенный Метод

Build GROUP BY
protected _build_group_by ( )

_build_having() защищенный Метод

Build the HAVING clause(s)
protected _build_having ( )

_build_insert() защищенный Метод

Build an INSERT query
protected _build_insert ( )

_build_join() защищенный Метод

Build the JOIN sources
protected _build_join ( )

_build_limit() защищенный Метод

Build LIMIT
protected _build_limit ( )

_build_offset() защищенный Метод

Build OFFSET
protected _build_offset ( )

_build_order_by() защищенный Метод

Build ORDER BY
protected _build_order_by ( )

_build_select() защищенный Метод

Build a SELECT statement based on the clauses that have been passed to this instance by chaining method calls.
protected _build_select ( )

_build_select_start() защищенный Метод

Build the start of the SELECT statement
protected _build_select_start ( )

_build_update() защищенный Метод

Build an UPDATE query
protected _build_update ( )

_build_where() защищенный Метод

Build the WHERE clause(s)
protected _build_where ( )

_cache_query_result() защищенный статический Метод

Add the given value to the query cache.
protected static _cache_query_result ( $cache_key, $value, $table_name = null, $connection_name = self::DEFAULT_CONNECTION )

_call_aggregate_db_function() защищенный Метод

Execute an aggregate query on the current connection.
protected _call_aggregate_db_function ( string $sql_function, string $column ) : integer
$sql_function string The aggregate function to call eg. MIN, COUNT, etc
$column string The column to execute the aggregate query against
Результат integer

_check_query_cache() защищенный статический Метод

Check the query cache for the given cache key. If a value is cached for the key, return the value. Otherwise, return false.
protected static _check_query_cache ( $cache_key, $table_name = null, $connection_name = self::DEFAULT_CONNECTION )

_create_cache_key() защищенный статический Метод

Create a cache key for the given query and parameters.
protected static _create_cache_key ( $query, $parameters, $table_name = null, $connection_name = self::DEFAULT_CONNECTION )

_create_instance_from_row() защищенный Метод

Create an ORM instance from the given row (an associative array of data fetched from the database)
protected _create_instance_from_row ( $row )

_create_placeholders() защищенный Метод

Return a string containing the given number of question marks, separated by commas. Eg "?, ?, ?"
protected _create_placeholders ( $fields )

_detect_identifier_quote_character() защищенный статический Метод

Return the correct character used to quote identifiers (table names, column names etc) by looking at the driver being used by PDO.
protected static _detect_identifier_quote_character ( string $connection_name ) : string
$connection_name string Which connection to use
Результат string

_detect_limit_clause_style() защищенный статический Метод

Returns a constant after determining the appropriate limit clause style
protected static _detect_limit_clause_style ( string $connection_name ) : string
$connection_name string Which connection to use
Результат string Limit clause style keyword/constant

_execute() защищенный статический Метод

Internal helper method for executing statments. Logs queries, and stores statement object in ::_last_statment, accessible publicly through ::get_last_statement()
protected static _execute ( string $query, array $parameters = [], string $connection_name = self::DEFAULT_CONNECTION ) : boolean
$query string
$parameters array An array of parameters to be bound in to the query
$connection_name string Which connection to use
Результат boolean Response of PDOStatement::execute()

_find_many() защищенный Метод

Tell the ORM that you are expecting multiple results from your query, and execute it. Will return an array of instances of the ORM class, or an empty array if no rows were returned.
protected _find_many ( ) : array
Результат array

_get_compound_id_column_values() защищенный Метод

If the key contains a column that does not exist in the given array, a null value will be returned for it.
protected _get_compound_id_column_values ( $value )

_get_compound_id_column_values_array() защищенный Метод

Helper method that filters an array containing compound column/value arrays.
protected _get_compound_id_column_values_array ( $values )

_get_id_column_name() защищенный Метод

Return the name of the column in the database table which contains the primary key ID of the row.
protected _get_id_column_name ( )

_join_if_not_empty() защищенный Метод

Wrapper around PHP's join function which only adds the pieces if they are not empty.
protected _join_if_not_empty ( $glue, $pieces )

_log_query() защищенный статический Метод

This works by manually binding the parameters to the query - the query isn't executed like this (PDO normally passes the query and parameters to the database which takes care of the binding) but doing it this way makes the logged queries more readable.
protected static _log_query ( string $query, array $parameters, string $connection_name, float $query_time ) : boolean
$query string
$parameters array An array of parameters to be bound in to the query
$connection_name string Which connection to use
$query_time float Query time
Результат boolean

_normalise_select_many_columns() защищенный Метод

It is designed to turn the following styles into a normalised array: array(array('alias' => 'column', 'column2', 'alias2' => 'column3'), 'column4', 'column5'))
protected _normalise_select_many_columns ( array $columns ) : array
$columns array
Результат array

_quote_identifier() защищенный Метод

Quote a string that is used as an identifier (table names, column names etc) or an array containing multiple identifiers. This method can also deal with dot-separated identifiers eg table.column
protected _quote_identifier ( $identifier )

_quote_identifier_part() защищенный Метод

This method performs the actual quoting of a single part of an identifier, using the identifier quote character specified in the config (or autodetected).
protected _quote_identifier_part ( $part )

_quote_one_identifier() защищенный Метод

Quote a string that is used as an identifier (table names, column names etc). This method can also deal with dot-separated identifiers eg table.column
protected _quote_one_identifier ( $identifier )

_run() защищенный Метод

Execute the SELECT query that has been built up by chaining methods on this class. Return an array of rows as associative arrays.
protected _run ( )

_set_orm_property() защищенный Метод

Set a property on the ORM object.
protected _set_orm_property ( string | array $key, string | null $value = null, $expr = false )
$key string | array
$value string | null

_setup_db() защищенный статический Метод

Set up the database connection used by the class
protected static _setup_db ( string $connection_name = self::DEFAULT_CONNECTION )
$connection_name string Which connection to use

_setup_db_config() защищенный статический Метод

Ensures configuration (multiple connections) is at least set to default.
protected static _setup_db_config ( string $connection_name )
$connection_name string Which connection to use

_setup_identifier_quote_character() защищенный статический Метод

Detect and initialise the character used to quote identifiers (table names, column names etc). If this has been specified manually using ORM::configure('identifier_quote_character', 'some-char'), this will do nothing.
protected static _setup_identifier_quote_character ( string $connection_name )
$connection_name string Which connection to use

_setup_limit_clause_style() публичный статический Метод

.. LIMIT 5"). If this has been specified manually using ORM::configure('limit_clause_style', 'top'), this will do nothing.
public static _setup_limit_clause_style ( string $connection_name )
$connection_name string Which connection to use

as_array() публичный Метод

Return the raw data wrapped by this ORM instance as an associative array. Column names may optionally be supplied as arguments, if so, only those keys will be returned.
public as_array ( )

avg() публичный Метод

Will return the average value of the choosen column.
public avg ( $column )

clear_cache() публичный статический Метод

Clear the query cache
public static clear_cache ( $table_name = null, $connection_name = self::DEFAULT_CONNECTION )

configure() публичный статический Метод

Pass configuration settings to the class in the form of key/value pairs. As a shortcut, if the second argument is omitted and the key is a string, the setting is assumed to be the DSN string used by PDO to connect to the database (often, this will be the only configuration required to use Idiorm). If you have more than one setting you wish to configure, another shortcut is to pass an array of settings (and omit the second argument).
public static configure ( string $key, mixed $value = null, string $connection_name = self::DEFAULT_CONNECTION )
$key string
$value mixed
$connection_name string Which connection to use

count() публичный Метод

Will return an integer representing the number of rows returned.
public count ( $column = '*' )

count_null_id_columns() публичный Метод

Counts the number of columns that belong to the primary key and their value is null.

create() публичный Метод

Create a new, empty instance of the class. Used to add a new row to your database. May optionally be passed an associative array of data to populate the instance. If so, all fields will be flagged as dirty so all will be saved to the database when save() is called.
public create ( $data = null )

delete() публичный Метод

Delete this record from the database
public delete ( )

delete_many() публичный Метод

Delete many records from the database
public delete_many ( )

distinct() публичный Метод

Add a DISTINCT keyword before the list of columns in the SELECT query
public distinct ( )

find_array() публичный Метод

Tell the ORM that you are expecting multiple results from your query, and execute it. Will return an array, or an empty array if no rows were returned.
public find_array ( ) : array
Результат array

find_many() публичный Метод

Tell the ORM that you are expecting multiple results from your query, and execute it. Will return an array of instances of the ORM class, or an empty array if no rows were returned.
public find_many ( ) : array | IdiormResultSet
Результат array | IdiormResultSet

find_one() публичный Метод

As a shortcut, you may supply an ID as a parameter to this method. This will perform a primary key lookup on the table.
public find_one ( $id = null )

find_result_set() публичный Метод

Tell the ORM that you are expecting multiple results from your query, and execute it. Will return a result set object containing instances of the ORM class.
public find_result_set ( ) : IdiormResultSet
Результат IdiormResultSet

for_table() публичный статический Метод

Despite its slightly odd name, this is actually the factory method used to acquire instances of the class. It is named this way for the sake of a readable interface, ie ORM::for_table('table_name')->find_one()-> etc. As such, this will normally be the first method called in a chain.
public static for_table ( string $table_name, string $connection_name = self::DEFAULT_CONNECTION ) : ORM
$table_name string
$connection_name string Which connection to use
Результат ORM

force_all_dirty() публичный Метод

Force the ORM to flag all the fields in the $data array as "dirty" and therefore update them when save() is called.
public force_all_dirty ( )

full_outer_join() публичный Метод

Add an FULL OUTER JOIN souce to the query
public full_outer_join ( $table, $constraint, $table_alias = null )

get() публичный Метод

If a column-names array is passed, it will return a associative array with the value of each column or null if it is not present.
public get ( $key )

get_config() публичный статический Метод

Retrieve configuration options by key, or as whole array.
public static get_config ( string $key = null, string $connection_name = self::DEFAULT_CONNECTION )
$key string
$connection_name string Which connection to use

get_connection_names() публичный статический Метод

Get a list of the available connection names
public static get_connection_names ( ) : array
Результат array

get_db() публичный статический Метод

Returns the PDO instance used by the the ORM to communicate with the database. This can be called if any low-level DB access is required outside the class. If multiple connections are used, accepts an optional key name for the connection.
public static get_db ( string $connection_name = self::DEFAULT_CONNECTION ) : PDO
$connection_name string Which connection to use
Результат PDO

get_last_query() публичный статический Метод

Get the last query executed. Only works if the 'logging' config option is set to true. Otherwise this will return null. Returns last query from all connections if no connection_name is specified
public static get_last_query ( null | string $connection_name = null ) : string
$connection_name null | string Which connection to use
Результат string

get_last_statement() публичный статический Метод

Useful for access to PDOStatement::rowCount() or error information
public static get_last_statement ( ) : PDOStatement
Результат PDOStatement

get_query_log() публичный статический Метод

Only works if the 'logging' config option is set to true. Otherwise, returned array will be empty.
public static get_query_log ( string $connection_name = self::DEFAULT_CONNECTION )
$connection_name string Which connection to use

group_by() публичный Метод

Add a column to the list of columns to GROUP BY
public group_by ( $column_name )

group_by_expr() публичный Метод

Add an unquoted expression to the list of columns to GROUP BY
public group_by_expr ( $expr )

having() публичный Метод

If you use an array in $column_name, a new clause will be added for each element. In this case, $value is ignored.
public having ( $column_name, $value = null )

having_equal() публичный Метод

Can be used if preferred.
public having_equal ( $column_name, $value = null )

having_gt() публичный Метод

.. > clause to your query
public having_gt ( $column_name, $value = null )

having_gte() публичный Метод

.. >= clause to your query
public having_gte ( $column_name, $value = null )

having_id_is() публичный Метод

If primary key is compound, only the columns that belong to they key will be used for the query
public having_id_is ( $id )

having_in() публичный Метод

.. IN clause to your query
public having_in ( $column_name, $values = null )

having_like() публичный Метод

.. LIKE clause to your query.
public having_like ( $column_name, $value = null )

having_lt() публичный Метод

.. < clause to your query
public having_lt ( $column_name, $value = null )

having_lte() публичный Метод

.. <= clause to your query
public having_lte ( $column_name, $value = null )

having_not_equal() публичный Метод

Add a HAVING column != value clause to your query.
public having_not_equal ( $column_name, $value = null )

having_not_in() публичный Метод

.. NOT IN clause to your query
public having_not_in ( $column_name, $values = null )

having_not_like() публичный Метод

.. NOT LIKE clause to your query.
public having_not_like ( $column_name, $value = null )

having_not_null() публичный Метод

Add a HAVING column IS NOT NULL clause to your query
public having_not_null ( $column_name )

having_null() публичный Метод

Add a HAVING column IS NULL clause to your query
public having_null ( $column_name )

having_raw() публичный Метод

Add a raw HAVING clause to the query. The clause should contain question mark placeholders, which will be bound to the parameters supplied in the second argument.
public having_raw ( $clause, $parameters = [] )

hydrate() публичный Метод

This will usually be called only from inside the class, but it's public in case you need to call it directly.
public hydrate ( $data = [] )

id() публичный Метод

Get the primary key ID of this object.
public id ( $disallow_null = false )

inner_join() публичный Метод

Add an INNER JOIN souce to the query
public inner_join ( $table, $constraint, $table_alias = null )

is_dirty() публичный Метод

Check whether the given field has been changed since this object was saved.
public is_dirty ( $key )

is_new() публичный Метод

Check whether the model was the result of a call to create() or not
public is_new ( ) : boolean
Результат boolean

join() публичный Метод

Add a simple JOIN source to the query
public join ( $table, $constraint, $table_alias = null )

left_outer_join() публичный Метод

Add a LEFT OUTER JOIN souce to the query
public left_outer_join ( $table, $constraint, $table_alias = null )

limit() публичный Метод

Add a LIMIT to the query
public limit ( $limit )

max() публичный Метод

Will return the max value of the choosen column.
public max ( $column )

min() публичный Метод

Will return the min value of the choosen column.
public min ( $column )

offset() публичный Метод

Add an OFFSET to the query
public offset ( $offset )

offsetExists() публичный Метод

--------------------- //
public offsetExists ( $key )

offsetGet() публичный Метод

public offsetGet ( $key )

offsetSet() публичный Метод

public offsetSet ( $key, $value )

offsetUnset() публичный Метод

public offsetUnset ( $key )

order_by_asc() публичный Метод

Add an ORDER BY column ASC clause
public order_by_asc ( $column_name )

order_by_desc() публичный Метод

Add an ORDER BY column DESC clause
public order_by_desc ( $column_name )

order_by_expr() публичный Метод

Add an unquoted expression as an ORDER BY clause
public order_by_expr ( $clause )

raw_execute() публичный статический Метод

Useful for queries that can't be accomplished through Idiorm, particularly those using engine-specific features.
public static raw_execute ( string $query, array $parameters = [], string $connection_name = self::DEFAULT_CONNECTION ) : boolean
$query string The raw SQL query
$parameters array Optional bound parameters
$connection_name string Which connection to use
Результат boolean Success

raw_join() публичный Метод

Add a RAW JOIN source to the query
public raw_join ( $table, $constraint, $table_alias, $parameters = [] )

raw_query() публичный Метод

Perform a raw query. The query can contain placeholders in either named or question mark style. If placeholders are used, the parameters should be an array of values which will be bound to the placeholders in the query. If this method is called, all other query building methods will be ignored.
public raw_query ( $query, $parameters = [] )

reset_config() публичный статический Метод

Delete all configs in _config array.
public static reset_config ( )

reset_db() публичный статический Метод

Delete all registered PDO objects in _db array.
public static reset_db ( )

right_outer_join() публичный Метод

Add an RIGHT OUTER JOIN souce to the query
public right_outer_join ( $table, $constraint, $table_alias = null )

save() публичный Метод

Save any fields which have been modified on this object to the database.
public save ( )

select() публичный Метод

Add a column to the list of columns returned by the SELECT query. This defaults to '*'. The second optional argument is the alias to return the column as.
public select ( $column, $alias = null )

select_expr() публичный Метод

Add an unquoted expression to the list of columns returned by the SELECT query. The second optional argument is the alias to return the column as.
public select_expr ( $expr, $alias = null )

select_many() публичный Метод

Note that the alias must not be numeric - if you want a numeric alias then prepend it with some alpha chars. eg. a1
public select_many ( ) : ORM
Результат ORM

select_many_expr() публичный Метод

Note that the alias must not be numeric - if you want a numeric alias then prepend it with some alpha chars. eg. a1
public select_many_expr ( ) : ORM
Результат ORM

set() публичный Метод

To set multiple properties at once, pass an associative array as the first parameter and leave out the second parameter. Flags the properties as 'dirty' so they will be saved to the database when save() is called.
public set ( $key, $value = null )

set_db() публичный статический Метод

This is public in case the ORM should use a ready-instantiated PDO object as its database connection. Accepts an optional string key to identify the connection if multiple connections are used.
public static set_db ( PDO $db, string $connection_name = self::DEFAULT_CONNECTION )
$db PDO
$connection_name string Which connection to use

set_expr() публичный Метод

To set multiple properties at once, pass an associative array as the first parameter and leave out the second parameter. Flags the properties as 'dirty' so they will be saved to the database when save() is called.
public set_expr ( string | array $key, string | null $value = null )
$key string | array
$value string | null

sum() публичный Метод

Will return the sum of the choosen column.
public sum ( $column )

table_alias() публичный Метод

Add an alias for the main table to be used in SELECT queries
public table_alias ( $alias )

use_id_column() публичный Метод

This overrides the id_column and id_column_overrides settings. This is mostly useful for libraries built on top of Idiorm, and will not normally be used in manually built queries. If you don't know why you would want to use this, you should probably just ignore it.
public use_id_column ( $id_column )

where() публичный Метод

If you use an array in $column_name, a new clause will be added for each element. In this case, $value is ignored.
public where ( $column_name, $value = null )

where_any_is() публичный Метод

By default, an equal operator will be used against all columns, but it can be overriden for any or every column using the second parameter. Each condition will be ORed together when added to the final query.
public where_any_is ( $values, $operator = '=' )

where_equal() публичный Метод

Can be used if preferred.
public where_equal ( $column_name, $value = null )

where_gt() публичный Метод

.. > clause to your query
public where_gt ( $column_name, $value = null )

where_gte() публичный Метод

.. >= clause to your query
public where_gte ( $column_name, $value = null )

where_id_in() публичный Метод

If primary key is compound, only the columns that belong to they key will be used for the query
public where_id_in ( $ids )

where_id_is() публичный Метод

If primary key is compound, only the columns that belong to they key will be used for the query
public where_id_is ( $id )

where_in() публичный Метод

.. IN clause to your query
public where_in ( $column_name, $values )

where_like() публичный Метод

.. LIKE clause to your query.
public where_like ( $column_name, $value = null )

where_lt() публичный Метод

.. < clause to your query
public where_lt ( $column_name, $value = null )

where_lte() публичный Метод

.. <= clause to your query
public where_lte ( $column_name, $value = null )

where_not_equal() публичный Метод

Add a WHERE column != value clause to your query.
public where_not_equal ( $column_name, $value = null )

where_not_in() публичный Метод

.. NOT IN clause to your query
public where_not_in ( $column_name, $values )

where_not_like() публичный Метод

.. NOT LIKE clause to your query.
public where_not_like ( $column_name, $value = null )

where_not_null() публичный Метод

Add a WHERE column IS NOT NULL clause to your query
public where_not_null ( $column_name )

where_null() публичный Метод

Add a WHERE column IS NULL clause to your query
public where_null ( $column_name )

where_raw() публичный Метод

Add a raw WHERE clause to the query. The clause should contain question mark placeholders, which will be bound to the parameters supplied in the second argument.
public where_raw ( $clause, $parameters = [] )

Описание свойств

$_config защищенное статическое свойство

Map of configuration settings
protected static $_config

$_connection_name защищенное свойство

Key name of the connections in self::$_db used by this instance
protected $_connection_name

$_data защищенное свойство

The data for a hydrated instance of the class
protected $_data

$_db защищенное статическое свойство

Map of database connections, instances of the PDO class
protected static $_db

$_default_config защищенное статическое свойство

Class configuration
protected static $_default_config

$_dirty_fields защищенное свойство

lifetime of the object
protected $_dirty_fields

$_distinct защищенное свойство

Should the query include a DISTINCT keyword?
protected $_distinct

$_expr_fields защищенное свойство

Fields that are to be inserted in the DB raw
protected $_expr_fields

$_group_by защищенное свойство

GROUP BY
protected $_group_by

$_having_conditions защищенное свойство

HAVING
protected $_having_conditions

$_instance_id_column защищенное свойство

this instance only. Overrides the config settings.
protected $_instance_id_column

$_is_new защищенное свойство

Is this a new object (has create() been called)?
protected $_is_new

$_is_raw_query защищенное свойство

Is this a raw query?
protected $_is_raw_query

$_join_sources защищенное свойство

Join sources
protected $_join_sources

$_last_query защищенное статическое свойство

Last query run, only populated if logging is enabled
protected static $_last_query

$_last_statement защищенное статическое свойство

Reference to previously used PDOStatement object to enable low-level access, if needed
protected static $_last_statement

$_limit защищенное свойство

LIMIT
protected $_limit

$_offset защищенное свойство

OFFSET
protected $_offset

$_order_by защищенное свойство

ORDER BY
protected $_order_by

$_query_cache защищенное статическое свойство

Query cache, only used if query caching is enabled
protected static $_query_cache

$_query_log защищенное статическое свойство

Log of all queries run, mapped by connection key, only populated if logging is enabled
protected static $_query_log

$_raw_parameters защищенное свойство

The raw query parameters
protected $_raw_parameters

$_raw_query защищенное свойство

The raw query
protected $_raw_query

$_result_columns защищенное свойство

Columns to select in the result
protected $_result_columns

$_table_alias защищенное свойство

Alias for the table to be used in SELECT queries
protected $_table_alias

$_table_name защищенное свойство

The name of the table the current ORM instance is associated with
protected $_table_name

$_using_default_result_columns защищенное свойство

Are we using the default result column or have these been manually changed?
protected $_using_default_result_columns

$_values защищенное свойство

Values to be bound to the query
protected $_values

$_where_conditions защищенное свойство

Array of WHERE clauses
protected $_where_conditions