PHP 클래스 Granada\ORM

Copyright (c) 2013, Erik Wiesenthal All rights reserved http://github.com/Surt/Granada/ Idiorm with some small changes ( http://github.com/Surt/Granada/ ). 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.
상속: implements ArrayAcces\ArrayAccess
파일 보기 프로젝트 열기: surt/granada 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$resultSetClass name of the ResultSet Object

보호된 프로퍼티들

프로퍼티 타입 설명
$_associative_results associative results flag
$_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 )
_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.
associative ( ) : ORM Set the ORM instance to return associative results sets
avg ( string $column ) Tell the ORM that you wish to execute a AVG query.
clear_cache ( ) 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.
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 ( $join = false, $table = false ) Delete many records from the database Added: could delete many of a join query, if you define $join to true and the table where you want to delete the records
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 | granada\ResultSet 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 ( ) : granada\ResultSet 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 ( string $table, string[] $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 ( string $column_name ) Add a column to the list of columns to GROUP BY
group_by_expr ( string $expr ) Add an unquoted expression to the list of columns to GROUP BY
having ( $column_name, $value ) 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 ) More explicitly named version of for the having() method.
having_gt ( string $column_name, integer $value ) Add a HAVING .
having_gte ( string $column_name, integer $value ) Add a HAVING .
having_id_is ( $id ) Special method to query the table by its primary key
having_in ( string $column_name, string[] $values ) Add a HAVING .
having_like ( string $column_name, string $value ) Add a HAVING .
having_lt ( string $column_name, integer $value ) Add a HAVING .
having_lte ( string $column_name, integer $value ) Add a HAVING .
having_not_equal ( string $column_name, string $value ) Add a HAVING column != value clause to your query.
having_not_in ( string $column_name, string[] $values ) Add a HAVING .
having_not_like ( string $column_name, string $value ) Add where HAVING .
having_not_null ( string $column_name ) Add a HAVING column IS NOT NULL clause to your query
having_null ( string $column_name ) Add a HAVING column IS NULL clause to your query
having_raw ( string $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 ( ) Get the primary key ID of this object.
inner_join ( string $table, string[] $constraint, $table_alias = null ) Add an INNER JOIN souce to the query
is_dirty ( string $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, string $table_alias = null ) Add a simple JOIN source to the query
left_outer_join ( string $table, string[] $constraint, $table_alias = null ) Add a LEFT OUTER JOIN souce to the query
limit ( integer $limit ) Add a LIMIT to the query
list_dirty_fields ( ) List the dirty fields that need updating on next save
max ( string $column ) Tell the ORM that you wish to execute a MAX query.
min ( string $column ) Tell the ORM that you wish to execute a MIN query.
non_associative ( ) : ORM Set the ORM instance to return non associative results sets
offset ( integer $offset ) Add an OFFSET to the query
offsetExists ( $key ) --------------------- //
offsetGet ( $key )
offsetSet ( $key, $value )
offsetUnset ( $key )
order_by_asc ( boolean | string $column_name ) Add an ORDER BY column ASC clause
order_by_desc ( string $column_name ) Add an ORDER BY column DESC clause
order_by_expr ( string $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_query ( string $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_associative ( ) : ORM Set the ORM instance to return associative (or not) results sets, as config dictates
reset_config ( ) Delete all configs in _config array.
reset_db ( ) Delete all registered PDO objects in _db array.
right_outer_join ( string $table, string[] $constraint, $table_alias = null ) Add an RIGHT OUTER JOIN souce to the query
save ( $ignore = false ) Save any fields which have been modified on this object to the database.
select ( $column, string $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 ( string $column ) Tell the ORM that you wish to execute a SUM query.
table_alias ( string $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 ) 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_equal ( $column_name, $value ) More explicitly named version of for the where() method.
where_gt ( string $column_name, integer $value ) Add a WHERE .
where_gte ( string $column_name, integer $value ) Add a WHERE .
where_id_is ( $id ) Special method to query the table by its primary key
where_in ( $column_name, $values ) Add a WHERE .
where_like ( string $column_name, string $value ) Add a WHERE .
where_lt ( string $column_name, integer $value ) Add a WHERE .
where_lte ( string $column_name, integer $value ) Add a WHERE .
where_not_equal ( string $column_name, string $value ) Add a WHERE column != value clause to your query.
where_not_in ( string $column_name, string[] $values ) Add a WHERE .
where_not_like ( string $column_name, string $value ) Add where WHERE .
where_not_null ( string $column_name ) Add a WHERE column IS NOT NULL clause to your query
where_null ( string $column_name ) Add a WHERE column IS NULL clause to your query
where_raw ( string $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 ( string $join_operator, $table, $constraint, $table_alias = null ) Internal method to add a JOIN source to the query.
_add_order_by ( $column_name, string $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 ( string $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, string $separator, $value ) Internal method to add a HAVING condition to the query
_add_simple_where ( $column_name, string $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_insert_update ( ) Added: Build an INSERT ON DUPLICATE KEY UPDATE query Attention: This method only works on Mysql Databases
_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 ( string $cache_key, $value, $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 ( string $cache_key, $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 ) 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 ( $associative = true ) : 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_id_column_name ( ) Return the name of the column in the database table which contains the primary key ID of the row.
_get_instances ( array $rows ) : array Create instances of each row in the result and map them to an associative array with the primary IDs as the array keys.
_join_if_not_empty ( string $glue, $pieces ) : string 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 ) : 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). 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).
_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 (mulitple 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.
reset ( ) reset Idiorm after executing the query

메소드 상세

__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_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 ( string $join_operator, $table, $constraint, $table_alias = null )
$join_operator string

_add_order_by() 보호된 메소드

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

_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() 보호된 메소드

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
protected _add_simple_condition ( string $type, $column_name, $separator, $value )
$type string

_add_simple_having() 보호된 메소드

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

_add_simple_where() 보호된 메소드

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

_add_where() 보호된 메소드

Internal method to add a WHERE condition to the query
protected _add_where ( $fragment, $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_insert_update() 보호된 메소드

Added: Build an INSERT ON DUPLICATE KEY UPDATE query Attention: This method only works on Mysql Databases
protected _build_insert_update ( )

_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 ( string $cache_key, $value, $connection_name = self::DEFAULT_CONNECTION )
$cache_key string

_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 ( string $cache_key, $connection_name = self::DEFAULT_CONNECTION )
$cache_key string

_create_cache_key() 보호된 정적인 메소드

Create a cache key for the given query and parameters.
protected static _create_cache_key ( $query, $parameters )

_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 ( $associative = true ) : array
리턴 array

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

_get_instances() 보호된 메소드

Create instances of each row in the result and map them to an associative array with the primary IDs as the array keys.
protected _get_instances ( array $rows ) : array
$rows array
리턴 array

_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 ( string $glue, $pieces ) : string
$glue string
리턴 string

_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 ) : boolean
$query string
$parameters array An array of parameters to be bound in to the query
$connection_name string Which connection to use
리턴 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). 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 )

_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 (mulitple 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 ( )

associative() 공개 메소드

Set the ORM instance to return associative results sets
public associative ( ) : ORM
리턴 ORM instance

avg() 공개 메소드

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

clear_cache() 공개 정적인 메소드

Clear the query cache
public static clear_cache ( )

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 = '*' )

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 Added: could delete many of a join query, if you define $join to true and the table where you want to delete the records
public delete_many ( $join = false, $table = false )

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 | granada\ResultSet
리턴 array | granada\ResultSet

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 ( ) : granada\ResultSet
리턴 granada\ResultSet

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 ( string $table, string[] $constraint, $table_alias = null )
$table string
$constraint string[]

get() 공개 메소드

Return the value of a property of this object (database row) or null if 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 ( string $column_name )
$column_name string

group_by_expr() 공개 메소드

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

having() 공개 메소드

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.
public having ( $column_name, $value )

having_equal() 공개 메소드

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

having_gt() 공개 메소드

.. > clause to your query
public having_gt ( string $column_name, integer $value )
$column_name string
$value integer

having_gte() 공개 메소드

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

having_id_is() 공개 메소드

Special method to query the table by its primary key
public having_id_is ( $id )

having_in() 공개 메소드

.. IN clause to your query
public having_in ( string $column_name, string[] $values )
$column_name string
$values string[]

having_like() 공개 메소드

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

having_lt() 공개 메소드

.. < clause to your query
public having_lt ( string $column_name, integer $value )
$column_name string
$value integer

having_lte() 공개 메소드

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

having_not_equal() 공개 메소드

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

having_not_in() 공개 메소드

.. NOT IN clause to your query
public having_not_in ( string $column_name, string[] $values )
$column_name string
$values string[]

having_not_like() 공개 메소드

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

having_not_null() 공개 메소드

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

having_null() 공개 메소드

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

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 ( string $clause, $parameters = [] )
$clause string

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

inner_join() 공개 메소드

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

is_dirty() 공개 메소드

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

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, string $table_alias = null )
$table_alias string

left_outer_join() 공개 메소드

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

limit() 공개 메소드

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

list_dirty_fields() 공개 메소드

List the dirty fields that need updating on next save
public list_dirty_fields ( )

max() 공개 메소드

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

min() 공개 메소드

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

non_associative() 공개 메소드

Set the ORM instance to return non associative results sets
public non_associative ( ) : ORM
리턴 ORM instance

offset() 공개 메소드

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

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 ( boolean | string $column_name )
$column_name boolean | string

order_by_desc() 공개 메소드

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

order_by_expr() 공개 메소드

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

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_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 ( string $query, $parameters = [] )
$query string

reset() 보호된 메소드

reset Idiorm after executing the query
protected reset ( )

reset_associative() 공개 메소드

Set the ORM instance to return associative (or not) results sets, as config dictates
public reset_associative ( ) : ORM
리턴 ORM instance

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 ( string $table, string[] $constraint, $table_alias = null )
$table string
$constraint string[]

save() 공개 메소드

Added: on duplicate key update, only for mysql If you want to insert a record, or update it if any of the unique keys already exists on db
public save ( $ignore = false )

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, string $alias = null )
$alias string

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 ( string $column )
$column string

table_alias() 공개 메소드

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

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() 공개 메소드

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.
public where ( $column_name, $value )

where_equal() 공개 메소드

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

where_gt() 공개 메소드

.. > clause to your query
public where_gt ( string $column_name, integer $value )
$column_name string
$value integer

where_gte() 공개 메소드

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

where_id_is() 공개 메소드

Special method to query the table by its primary key
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 ( string $column_name, string $value )
$column_name string
$value string

where_lt() 공개 메소드

.. < clause to your query
public where_lt ( string $column_name, integer $value )
$column_name string
$value integer

where_lte() 공개 메소드

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

where_not_equal() 공개 메소드

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

where_not_in() 공개 메소드

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

where_not_like() 공개 메소드

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

where_not_null() 공개 메소드

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

where_null() 공개 메소드

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

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 ( string $clause, $parameters = [] )
$clause string

프로퍼티 상세

$_associative_results 보호되어 있는 프로퍼티

associative results flag
protected $_associative_results

$_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

$resultSetClass 공개적으로 프로퍼티

name of the ResultSet Object
public $resultSetClass