PHP 클래스 Prado\Data\TDbConnection

TDbConnection represents a connection to a database. TDbConnection works together with {@link TDbCommand}, {@link TDbDataReader} and {@link TDbTransaction} to provide data access to various DBMS in a common set of APIs. They are a thin wrapper of the {@link http://www.php.net/manual/en/ref.pdo.php PDO} PHP extension. To establish a connection, set {@link setActive Active} to true after specifying {@link setConnectionString ConnectionString}, {@link setUsername Username} and {@link setPassword Password}. Since 3.1.2, the connection charset can be set (for MySQL and PostgreSQL databases only) using the {@link setCharset Charset} property. The value of this property is database dependant. e.g. for mysql, you can use 'latin1' for cp1252 West European, 'utf8' for unicode, ... The following example shows how to create a TDbConnection instance and establish the actual connection: $connection=new TDbConnection($dsn,$username,$password); $connection->Active=true; After the DB connection is established, one can execute an SQL statement like the following: $command=$connection->createCommand($sqlStatement); $command->execute(); // a non-query SQL statement execution or execute an SQL query and fetch the result set $reader=$command->query(); each $row is an array representing a row of data foreach($reader as $row) ... One can do prepared SQL execution and bind parameters to the prepared SQL: $command=$connection->createCommand($sqlStatement); $command->bindParameter($name1,$value1); $command->bindParameter($name2,$value2); $command->execute(); To use transaction, do like the following: $transaction=$connection->beginTransaction(); try { $connection->createCommand($sql1)->execute(); $connection->createCommand($sql2)->execute(); .... other SQL executions $transaction->commit(); } catch(Exception $e) { $transaction->rollBack(); } TDbConnection provides a set of methods to support setting and querying of certain DBMS attributes, such as {@link getNullConversion NullConversion}.
부터: 3.0
저자: Qiang Xue ([email protected])
상속: extends Prado\TComponent
파일 보기 프로젝트 열기: pradosoft/prado 1 사용 예제들

공개 메소드들

메소드 설명
__construct ( $dsn = '', $username = '', $password = '', $charset = '' ) Constructor.
__sleep ( ) Close the connection when serializing.
beginTransaction ( ) : TDbTransaction Starts a transaction.
createCommand ( $sql ) : TDbCommand Creates a command for execution.
getActive ( ) : boolean
getAttribute ( $name ) : mixed Obtains a specific DB connection attribute information.
getAutoCommit ( ) : boolean
getAvailableDrivers ( ) : array
getCharset ( ) : string
getClientVersion ( ) : string
getColumnCase ( ) : TDbColumnCaseMode
getConnectionStatus ( ) : string
getConnectionString ( ) : string
getCurrentTransaction ( ) : TDbTransaction
getDbMetaData ( ) : TDbMetaData
getDriverName ( ) : string
getLastInsertID ( $sequenceName = '' ) : string Returns the ID of the last inserted row or sequence value.
getNullConversion ( ) : TDbNullConversionMode
getPassword ( ) : string
getPdoInstance ( ) : PDO
getPersistent ( ) : boolean
getPrefetch ( ) : boolean
getServerInfo ( ) : string
getServerVersion ( ) : string
getTimeout ( ) : integer
getTransactionClass ( ) : string
getUsername ( ) : string
quoteColumnAlias ( string $name ) : string Quotes a column alias for use in a query.
quoteColumnName ( string $name ) : string Quotes a column name for use in a query.
quoteString ( $str ) : string Quotes a string for use in a query.
quoteTableName ( string $name ) : string Quotes a table name for use in a query.
setActive ( $value ) Open or close the DB connection.
setAttribute ( $name, $value ) Sets an attribute on the database connection.
setAutoCommit ( $value )
setCharset ( $value )
setColumnCase ( $value )
setConnectionString ( $value )
setNullConversion ( $value )
setPassword ( $value )
setPersistent ( $value )
setTransactionClass ( $value )
setUsername ( $value )

보호된 메소드들

메소드 설명
close ( ) Closes the currently active DB connection.
open ( ) Opens DB connection if it is currently not
setConnectionCharset ( ) * Set the database connection charset.

메소드 상세

__construct() 공개 메소드

Note, the DB connection is not established when this connection instance is created. Set {@link setActive Active} property to true to establish the connection. Since 3.1.2, you can set the charset for MySql connection
또한 보기: http://www.php.net/manual/en/function.PDO-construct.php
public __construct ( $dsn = '', $username = '', $password = '', $charset = '' )

__sleep() 공개 메소드

Close the connection when serializing.
public __sleep ( )

beginTransaction() 공개 메소드

Starts a transaction.
public beginTransaction ( ) : TDbTransaction
리턴 TDbTransaction the transaction initiated

close() 보호된 메소드

It does nothing if the connection is already closed.
protected close ( )

createCommand() 공개 메소드

Creates a command for execution.
public createCommand ( $sql ) : TDbCommand
리턴 TDbCommand the DB command

getActive() 공개 메소드

public getActive ( ) : boolean
리턴 boolean whether the DB connection is established

getAttribute() 공개 메소드

Obtains a specific DB connection attribute information.
또한 보기: http://www.php.net/manual/en/function.PDO-getAttribute.php
public getAttribute ( $name ) : mixed
리턴 mixed the corresponding attribute information

getAutoCommit() 공개 메소드

public getAutoCommit ( ) : boolean
리턴 boolean whether creating or updating a DB record will be automatically committed. Some DBMS (such as sqlite) may not support this feature.

getAvailableDrivers() 공개 정적인 메소드

또한 보기: http://www.php.net/manual/en/function.PDO-getAvailableDrivers.php
public static getAvailableDrivers ( ) : array
리턴 array list of available PDO drivers

getCharset() 공개 메소드

public getCharset ( ) : string
리턴 string the charset used for database connection. Defaults to emtpy string.

getClientVersion() 공개 메소드

public getClientVersion ( ) : string
리턴 string the version information of the DB driver

getColumnCase() 공개 메소드

public getColumnCase ( ) : TDbColumnCaseMode
리턴 TDbColumnCaseMode the case of the column names

getConnectionStatus() 공개 메소드

public getConnectionStatus ( ) : string
리턴 string the status of the connection Some DBMS (such as sqlite) may not support this feature.

getConnectionString() 공개 메소드

public getConnectionString ( ) : string
리턴 string The Data Source Name, or DSN, contains the information required to connect to the database.

getCurrentTransaction() 공개 메소드

public getCurrentTransaction ( ) : TDbTransaction
리턴 TDbTransaction the currently active transaction. Null if no active transaction.

getDbMetaData() 공개 메소드

public getDbMetaData ( ) : TDbMetaData
리턴 Prado\Data\Common\TDbMetaData

getDriverName() 공개 메소드

public getDriverName ( ) : string
리턴 string name of the DB driver

getLastInsertID() 공개 메소드

Returns the ID of the last inserted row or sequence value.
또한 보기: http://www.php.net/manual/en/function.PDO-lastInsertId.php
public getLastInsertID ( $sequenceName = '' ) : string
리턴 string the row ID of the last row inserted, or the last value retrieved from the sequence object

getNullConversion() 공개 메소드

public getNullConversion ( ) : TDbNullConversionMode
리턴 TDbNullConversionMode how the null and empty strings are converted

getPassword() 공개 메소드

public getPassword ( ) : string
리턴 string the password for establishing DB connection. Defaults to empty string.

getPdoInstance() 공개 메소드

public getPdoInstance ( ) : PDO
리턴 PDO the PDO instance, null if the connection is not established yet

getPersistent() 공개 메소드

public getPersistent ( ) : boolean
리턴 boolean whether the connection is persistent or not Some DBMS (such as sqlite) may not support this feature.

getPrefetch() 공개 메소드

public getPrefetch ( ) : boolean
리턴 boolean whether the connection performs data prefetching

getServerInfo() 공개 메소드

public getServerInfo ( ) : string
리턴 string the information of DBMS server

getServerVersion() 공개 메소드

public getServerVersion ( ) : string
리턴 string the version information of DBMS server

getTimeout() 공개 메소드

public getTimeout ( ) : integer
리턴 integer timeout settings for the connection

getTransactionClass() 공개 메소드

부터: 3.1.7
public getTransactionClass ( ) : string
리턴 string Transaction class name to be created by calling {@link TDbConnection::beginTransaction}. Defaults to 'System.Data.TDbTransaction'.

getUsername() 공개 메소드

public getUsername ( ) : string
리턴 string the username for establishing DB connection. Defaults to empty string.

open() 보호된 메소드

Opens DB connection if it is currently not
protected open ( )

quoteColumnAlias() 공개 메소드

Quotes a column alias for use in a query.
public quoteColumnAlias ( string $name ) : string
$name string column name
리턴 string the properly quoted column alias

quoteColumnName() 공개 메소드

Quotes a column name for use in a query.
public quoteColumnName ( string $name ) : string
$name string column name
리턴 string the properly quoted column name

quoteString() 공개 메소드

Quotes a string for use in a query.
또한 보기: http://www.php.net/manual/en/function.PDO-quote.php
public quoteString ( $str ) : string
리턴 string the properly quoted string

quoteTableName() 공개 메소드

Quotes a table name for use in a query.
public quoteTableName ( string $name ) : string
$name string table name
리턴 string the properly quoted table name

setActive() 공개 메소드

Open or close the DB connection.
public setActive ( $value )

setAttribute() 공개 메소드

Sets an attribute on the database connection.
또한 보기: http://www.php.net/manual/en/function.PDO-setAttribute.php
public setAttribute ( $name, $value )

setAutoCommit() 공개 메소드

public setAutoCommit ( $value )

setCharset() 공개 메소드

public setCharset ( $value )

setColumnCase() 공개 메소드

public setColumnCase ( $value )

setConnectionCharset() 보호된 메소드

Only MySql databases are supported for now.
부터: 3.1.2
protected setConnectionCharset ( )

setConnectionString() 공개 메소드

또한 보기: http://www.php.net/manual/en/function.PDO-construct.php
public setConnectionString ( $value )

setNullConversion() 공개 메소드

public setNullConversion ( $value )

setPassword() 공개 메소드

public setPassword ( $value )

setPersistent() 공개 메소드

public setPersistent ( $value )

setTransactionClass() 공개 메소드

부터: 3.1.7
public setTransactionClass ( $value )

setUsername() 공개 메소드

public setUsername ( $value )