PHP 클래스 Prado\Data\DataGateway\TTableGateway

Each method maps the input parameters into a SQL call and executes the SQL against a database connection. The TTableGateway is stateless (with respect to the data and data objects), as its role is to push data back and forth. Example usage: create a connection $dsn = 'pgsql:host=localhost;dbname=test'; $conn = new TDbConnection($dsn, 'dbuser','dbpass'); create a table gateway for table/view named 'address' $table = new TTableGateway('address', $conn); insert a new row, returns last insert id (if applicable) $id = $table->insert(array('name'=>'wei', 'phone'=>'111111')); $record1 = $table->findByPk($id); //find inserted record finds all records, returns an iterator $records = $table->findAll(); print_r($records->readAll()); update the row $table->updateByPk($record1, $id); All methods that may return more than one row of data will return an TDbDataReader iterator. The OnCreateCommand event is raised when a command is prepared and parameter binding is completed. The parameter object is a TDataGatewayEventParameter of which the {@link TDataGatewayEventParameter::getCommand Command} property can be inspected to obtain the sql query to be executed. The OnExecuteCommand event is raised when a command is executed and the result from the database was returned. The parameter object is a TDataGatewayResultEventParameter of which the {@link TDataGatewayEventParameter::getResult Result} property contains the data return from the database. The data returned can be changed by setting the {@link TDataGatewayEventParameter::setResult Result} property. $table->OnCreateCommand[] = 'log_it'; //any valid PHP callback statement $table->OnExecuteCommand[] = array($obj, 'method_name'); // calls 'method_name' on $obj function log_it($sender, $param) { var_dump($param); //TDataGatewayEventParameter object. }
부터: 3.1
상속: extends Prado\TComponent
파일 보기 프로젝트 열기: pradosoft/prado

공개 메소드들

메소드 설명
__call ( $method, $args ) : mixed Dynamic find method using parts of method name as search criteria.
__construct ( $table, $connection ) Creates a new generic table gateway for a given table or view name and a database connection.
count ( $criteria = null, $parameters = [] ) : integer Find the number of records.
deleteAll ( $criteria, $parameters = [] ) : integer Delete records from the table with condition given by $where and binding values specified by $parameter argument.
deleteAllByPks ( $keys ) Alias for deleteByPk()
deleteByPk ( $keys ) : integer Delete records by primary key. Usage:
find ( $criteria, $parameters = [] ) : array Find one single record that matches the criteria.
findAll ( $criteria = null, $parameters = [] ) : TDbDataReader Accepts same parameters as find(), but returns TDbDataReader instead.
findAllByPks ( $keys ) : TDbDataReader Similar to findByPk(), but returns TDbDataReader instead.
findAllBySql ( $sql, $parameters = [] ) : TDbDataReader Execute arbituary sql command with binding parameters.
findByPk ( $keys ) : array Find one record using only the primary key or composite primary keys. Usage:
findBySql ( $sql, $parameters = [] ) : array Execute arbituary sql command with binding parameters.
getDbConnection ( ) : TDbConnection
getLastInsertId ( ) : mixed
getTableInfo ( )
getTableName ( )
insert ( $data ) : mixed Inserts a new record into the table. Each array key must correspond to a column name in the table unless a null value is permitted.
onCreateCommand ( $sender, $param ) Raised when a command is prepared and parameter binding is completed.
onExecuteCommand ( $sender, $param ) Raised when a command is executed and the result from the database was returned.
update ( $data, $criteria, $parameters = [] ) : integer Updates the table with new name-value pair $data. Each array key must correspond to a column name in the table. The update condition is specified by the $where argument and additional binding values can be specified using the $parameter argument.

보호된 메소드들

메소드 설명
getCommand ( ) : TDataGatewayCommand
getCriteria ( $criteria, $parameters, $args ) : TSqlCriteria Create a new TSqlCriteria object from a string $criteria. The $args are additional parameters and are used in place of the $parameters if $parameters is not an array and $args is an arrary.
initCommandBuilder ( $builder )
setTableInfo ( $tableInfo )
setTableName ( $tableName ) Sets up the command builder for the given table.

메소드 상세

__call() 공개 메소드

Method name starting with "findBy" only returns 1 record. Method name starting with "findAllBy" returns 0 or more records. Method name starting with "deleteBy" deletes records by the trail criteria. The condition is taken as part of the method name after "findBy", "findAllBy" or "deleteBy". The following are equivalent: $table->findByName($name) $table->find('Name = ?', $name); $table->findByUsernameAndPassword($name,$pass); // OR may be used $table->findBy_Username_And_Password($name,$pass); // _OR_ may be used $table->find('Username = ? AND Password = ?', $name, $pass); $table->findAllByAge($age); $table->findAll('Age = ?', $age); $table->deleteAll('Name = ?', $name); $table->deleteByName($name);
public __call ( $method, $args ) : mixed
리턴 mixed single record if method name starts with "findBy", 0 or more records if method name starts with "findAllBy"

__construct() 공개 메소드

Creates a new generic table gateway for a given table or view name and a database connection.
public __construct ( $table, $connection )

count() 공개 메소드

Find the number of records.
public count ( $criteria = null, $parameters = [] ) : integer
리턴 integer number of records.

deleteAll() 공개 메소드

This method uses additional arguments as $parameters. E.g. $table->delete('age > ? AND location = ?', $age, $location);
public deleteAll ( $criteria, $parameters = [] ) : integer
리턴 integer number of records deleted.

deleteAllByPks() 공개 메소드

Alias for deleteByPk()
public deleteAllByPks ( $keys )

deleteByPk() 공개 메소드

$table->deleteByPk($primaryKey); //delete 1 record $table->deleteByPk($key1,$key2,...); //delete multiple records $table->deleteByPk(array($key1,$key2,...)); //delete multiple records For composite primary keys (determined from the table definitions): $table->deleteByPk(array($key1,$key2)); //delete 1 record delete multiple records $table->deleteByPk(array($key1,$key2), array($key3,$key4),...); delete multiple records $table->deleteByPk(array( array($key1,$key2), array($key3,$key4), .. ));
public deleteByPk ( $keys ) : integer
리턴 integer number of records deleted.

find() 공개 메소드

Usage: $table->find('username = :name AND password = :pass', array(':name'=>$name, ':pass'=>$pass)); $table->find('username = ? AND password = ?', array($name, $pass)); $table->find('username = ? AND password = ?', $name, $pass); $criteria is of TSqlCriteria $table->find($criteria); //the 2nd parameter for find() is ignored.
public find ( $criteria, $parameters = [] ) : array
리턴 array matching record object.

findAll() 공개 메소드

Accepts same parameters as find(), but returns TDbDataReader instead.
public findAll ( $criteria = null, $parameters = [] ) : TDbDataReader
리턴 TDbDataReader matching records.

findAllByPks() 공개 메소드

For scalar primary keys: $table->findAllByPk($key1, $key2, ...); $table->findAllByPk(array($key1, $key2, ...)); For composite keys: $table->findAllByPk(array($key1, $key2), array($key3, $key4), ...); $table->findAllByPk(array(array($key1, $key2), array($key3, $key4), ...));
public findAllByPks ( $keys ) : TDbDataReader
리턴 TDbDataReader data reader.

findAllBySql() 공개 메소드

Execute arbituary sql command with binding parameters.
public findAllBySql ( $sql, $parameters = [] ) : TDbDataReader
리턴 TDbDataReader query results.

findByPk() 공개 메소드

$table->findByPk($primaryKey); $table->findByPk($key1, $key2, ...); $table->findByPk(array($key1,$key2,...));
public findByPk ( $keys ) : array
리턴 array matching record.

findBySql() 공개 메소드

Execute arbituary sql command with binding parameters.
public findBySql ( $sql, $parameters = [] ) : array
리턴 array query results.

getCommand() 보호된 메소드

protected getCommand ( ) : TDataGatewayCommand
리턴 TDataGatewayCommand command builder and executor.

getCriteria() 보호된 메소드

Create a new TSqlCriteria object from a string $criteria. The $args are additional parameters and are used in place of the $parameters if $parameters is not an array and $args is an arrary.
protected getCriteria ( $criteria, $parameters, $args ) : TSqlCriteria
리턴 TSqlCriteria criteria object.

getDbConnection() 공개 메소드

public getDbConnection ( ) : TDbConnection
리턴 TDbConnection database connection.

getLastInsertId() 공개 메소드

public getLastInsertId ( ) : mixed
리턴 mixed last insert id, null if none is found.

getTableInfo() 공개 메소드

public getTableInfo ( )

getTableName() 공개 메소드

public getTableName ( )

initCommandBuilder() 보호된 메소드

protected initCommandBuilder ( $builder )

insert() 공개 메소드

Inserts a new record into the table. Each array key must correspond to a column name in the table unless a null value is permitted.
public insert ( $data ) : mixed
리턴 mixed last insert id if one column contains a serial or sequence, otherwise true if command executes successfully and affected 1 or more rows.

onCreateCommand() 공개 메소드

The parameter object is TDataGatewayEventParameter of which the {@link TDataGatewayEventParameter::getCommand Command} property can be inspected to obtain the sql query to be executed.
public onCreateCommand ( $sender, $param )

onExecuteCommand() 공개 메소드

The parameter object is TDataGatewayResultEventParameter of which the {@link TDataGatewayEventParameter::getResult Result} property contains the data return from the database. The data returned can be changed by setting the {@link TDataGatewayEventParameter::setResult Result} property.
public onExecuteCommand ( $sender, $param )

setTableInfo() 보호된 메소드

protected setTableInfo ( $tableInfo )

setTableName() 보호된 메소드

Sets up the command builder for the given table.
protected setTableName ( $tableName )

update() 공개 메소드

This method uses additional arguments as $parameters. E.g. $gateway->update($data, 'age > ? AND location = ?', $age, $location);
public update ( $data, $criteria, $parameters = [] ) : integer
리턴 integer number of records updated.