PHP 클래스 LazyRecord\ConnectionManager

$connManager = ConnectionManager::getInstance(); $conn = $connManager->create( '{{id}}', '' ); $conn = $connManager->default(); // return PDO connection object $result = $conn->query( ); $stm = $conn->prepare( ); $stm->execute( ); foreach( $connManager as $dataSourceId => $dataSourceConfig ) { }
상속: implements ArrayAcces\ArrayAccess
파일 보기 프로젝트 열기: corneltek/lazyrecord 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$conns contains PDO connection objects.
$datasources contains data source configurations

공개 메소드들

메소드 설명
__destruct ( )
add ( Connection $conn, string $id = 'default' ) Add connection.
addDataSource ( string $id, array $config ) Add custom data source:.
close ( $sourceId ) Close connection.
closeAll ( ) Close all connections.
free ( ) free connections, reset data sources.
get ( $dsId )
getConnection ( $sourceId ) Create connection.
getDataSource ( $id ) : array Get datasource config.
getDataSourceIdList ( ) : array Return datasource id(s).
getDefaultConnection ( ) : string Get default data source id.
getDriverType ( $id )
getInstance ( ) Get singleton instance.
getQueryDriver ( string $id ) : LazyRecord\QueryDriver Get SQLBuilder\QueryDriver by data source id.
has ( string $id ) Check if we have connected already.
hasDataSource ( $id = 'default' )
init ( ConfigLoader $config )
offsetExists ( string $name ) Check if a connection exists.
offsetGet ( string $name ) Get connection by data source id.
offsetSet ( string $name, Connection $value ) ArrayAccess interface.
offsetUnset ( $name )
prepareAndExecute ( $dsId, $sql, array $args = [] )
query ( $dsId, string $sql ) get pdo connetion and make a query.
removeDataSource ( $id )

메소드 상세

__destruct() 공개 메소드

public __destruct ( )

add() 공개 메소드

Add connection.
public add ( Connection $conn, string $id = 'default' )
$conn Connection pdo connection
$id string data source id

addDataSource() 공개 메소드

source config:
public addDataSource ( string $id, array $config )
$id string data source id
$config array data source config

close() 공개 메소드

Close connection.
public close ( $sourceId )

closeAll() 공개 메소드

Close all connections.
public closeAll ( )

free() 공개 메소드

free connections, reset data sources.
public free ( )

get() 공개 메소드

public get ( $dsId )

getConnection() 공개 메소드

$dbh = new Connection('mysql:host=localhost;dbname=test', $user, $pass); $pdo = new Connection( 'mysql:host=hostname;dbname=defaultDbName', 'username', 'password', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") ); $dbh = new Connection('pgsql:dbname=$dbname; host=$host; username=$username; password=$password'); $pdo = new Connection( 'sqlite::memory:', null, null, array(PDO::ATTR_PERSISTENT => true) ); sqlite2:mydb.sq2
public getConnection ( $sourceId )

getDataSource() 공개 메소드

Get datasource config.
public getDataSource ( $id ) : array
리턴 array

getDataSourceIdList() 공개 메소드

Return datasource id(s).
public getDataSourceIdList ( ) : array
리턴 array key list

getDefaultConnection() 공개 메소드

Get default data source id.
public getDefaultConnection ( ) : string
리턴 string 'default'

getDriverType() 공개 메소드

public getDriverType ( $id )

getInstance() 공개 정적인 메소드

Get singleton instance.
public static getInstance ( )

getQueryDriver() 공개 메소드

Get SQLBuilder\QueryDriver by data source id.
public getQueryDriver ( string $id ) : LazyRecord\QueryDriver
$id string datasource name
리턴 LazyRecord\QueryDriver

has() 공개 메소드

Check if we have connected already.
public has ( string $id )
$id string data source id.

hasDataSource() 공개 메소드

public hasDataSource ( $id = 'default' )

init() 공개 메소드

public init ( ConfigLoader $config )
$config ConfigLoader

offsetExists() 공개 메소드

Check if a connection exists.
public offsetExists ( string $name )
$name string

offsetGet() 공개 메소드

Get connection by data source id.
public offsetGet ( string $name )
$name string

offsetSet() 공개 메소드

ArrayAccess interface.
public offsetSet ( string $name, Connection $value )
$name string
$value Connection

offsetUnset() 공개 메소드

public offsetUnset ( $name )

prepareAndExecute() 공개 메소드

public prepareAndExecute ( $dsId, $sql, array $args = [] )
$args array

query() 공개 메소드

get pdo connetion and make a query.
public query ( $dsId, string $sql )
$sql string SQL statement

removeDataSource() 공개 메소드

public removeDataSource ( $id )

프로퍼티 상세

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

contains PDO connection objects.
protected $conns

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

contains data source configurations
protected $datasources