PHP 클래스 ManaPHP\Db

상속: extends Component, implements manaphp\DbInterface
파일 보기 프로젝트 열기: manaphp/manaphp 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_affectedRows integer Last affected rows
$_bind array Active SQL bound parameter variables
$_dsn string
$_options array
$_password string
$_pdo PDO
$_sql string Active SQL Statement
$_transactionLevel integer Current transaction level
$_type string Type of database system driver is used for
$_username string

공개 메소드들

메소드 설명
__construct ( array $options ) \ManaPHP\Db\Adapter constructor
affectedRows ( ) : integer Returns the number of affected rows by the last INSERT/UPDATE/DELETE reported by the database system
begin ( ) : void Starts a transaction in the connection
commit ( ) : void Commits the active transaction in the connection
delete ( string $table, string | array $conditions, array $bind = [] ) : integer Deletes data from a table using custom SQL syntax Deleting existing robot $success = $connection->delete( "robots", "id = 101" ); Next SQL sentence is generated DELETE FROM robots WHERE id = 101
execute ( string $sql, array $bind = [] ) : integer Sends SQL statements to the database server returning the success state.
fetchAll ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : array Dumps the complete result of a query into an array Getting all robots with associative indexes only $robots = $connection->fetchAll("SELECT * FROM robots", \ManaPHP\Db::FETCH_ASSOC); foreach ($robots as $robot) { print_r($robot); } Getting all robots that contains word "robot" withing the name $robots = $connection->fetchAll("SELECT * FROM robots WHERE name LIKE :name", ManaPHP\Db::FETCH_ASSOC, array('name' => '%robot%') ); foreach($robots as $robot){ print_r($robot); }
fetchOne ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : array | false Returns the first row in a SQL query result Getting first robot $robot = $connection->fetchOne("SELECT * FROM robots"); print_r($robot); Getting first robot with associative indexes only $robot = $connection->fetchOne("SELECT * FROM robots", \ManaPHP\Db::FETCH_ASSOC); print_r($robot);
getBind ( ) : array Active SQL statement in the object
getEmulatedSQL ( integer $preservedStrLength ) : string Active SQL statement in the object with replace the bind with value
getSQL ( ) : string Active SQL statement in the object
insert ( string $table, array $columnValues ) : void Inserts data into a table using custom SQL syntax Inserting a new robot $success = $connection->insert( "robots", array("Boy", 1952), array("name", "year") ); Next SQL sentence is sent to the database system INSERT INTO robots (name, year) VALUES ("boy", 1952);
isUnderTransaction ( ) : boolean Checks whether the connection is under a transaction $connection->begin(); var_dump($connection->isUnderTransaction()); //true
lastInsertId ( ) : integer Returns insert id for the auto_increment column inserted in the last SQL statement
limit ( string $sql, integer $number, integer $offset ) : string Appends a LIMIT clause to $sqlQuery argument echo $connection->limit("SELECT * FROM robots", 5);
query ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : PdoStatement Sends SQL statements to the database server returning the success state.
rollback ( ) : void Rollbacks the active transaction in the connection
update ( string $table, array $columnValues, string | array $conditions, array $bind = [] ) : integer Updates data on a table using custom SQL syntax Updating existing robot $success = $connection->update( "robots", array("name"), array("New Boy"), "id = 101" ); Next SQL sentence is sent to the database system UPDATE robots SET name = "boy" WHERE id = 101

보호된 메소드들

메소드 설명
_executePrepared ( PDOStatement $statement, array $bind ) : PDOStatement Executes a prepared statement binding. This function uses integer indexes starting from zero $statement = $db->prepare('SELECT * FROM robots WHERE name = :name'); $result = $connection->executePrepared($statement, array('name' => 'mana'));
_parseBindValue ( mixed $value, integer $preservedStrLength ) : integer | string

메소드 상세

__construct() 공개 메소드

\ManaPHP\Db\Adapter constructor
public __construct ( array $options )
$options array

_executePrepared() 보호된 메소드

Executes a prepared statement binding. This function uses integer indexes starting from zero $statement = $db->prepare('SELECT * FROM robots WHERE name = :name'); $result = $connection->executePrepared($statement, array('name' => 'mana'));
protected _executePrepared ( PDOStatement $statement, array $bind ) : PDOStatement
$statement PDOStatement
$bind array
리턴 PDOStatement

_parseBindValue() 보호된 메소드

protected _parseBindValue ( mixed $value, integer $preservedStrLength ) : integer | string
$value mixed
$preservedStrLength integer
리턴 integer | string

affectedRows() 공개 메소드

Returns the number of affected rows by the last INSERT/UPDATE/DELETE reported by the database system
public affectedRows ( ) : integer
리턴 integer

begin() 공개 메소드

Starts a transaction in the connection
public begin ( ) : void
리턴 void

commit() 공개 메소드

Commits the active transaction in the connection
public commit ( ) : void
리턴 void

delete() 공개 메소드

Deletes data from a table using custom SQL syntax Deleting existing robot $success = $connection->delete( "robots", "id = 101" ); Next SQL sentence is generated DELETE FROM robots WHERE id = 101
public delete ( string $table, string | array $conditions, array $bind = [] ) : integer
$table string
$conditions string | array
$bind array
리턴 integer

execute() 공개 메소드

Use this method only when the SQL statement sent to the server does n't return any rows Inserting data $success = $connection->execute("INSERT INTO robots VALUES (1, 'Boy')"); $success = $connection->execute("INSERT INTO robots VALUES (?, ?)", array(1, 'Boy'));
public execute ( string $sql, array $bind = [] ) : integer
$sql string
$bind array
리턴 integer

fetchAll() 공개 메소드

Dumps the complete result of a query into an array Getting all robots with associative indexes only $robots = $connection->fetchAll("SELECT * FROM robots", \ManaPHP\Db::FETCH_ASSOC); foreach ($robots as $robot) { print_r($robot); } Getting all robots that contains word "robot" withing the name $robots = $connection->fetchAll("SELECT * FROM robots WHERE name LIKE :name", ManaPHP\Db::FETCH_ASSOC, array('name' => '%robot%') ); foreach($robots as $robot){ print_r($robot); }
public fetchAll ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : array
$sql string
$bind array
$fetchMode integer
리턴 array

fetchOne() 공개 메소드

Returns the first row in a SQL query result Getting first robot $robot = $connection->fetchOne("SELECT * FROM robots"); print_r($robot); Getting first robot with associative indexes only $robot = $connection->fetchOne("SELECT * FROM robots", \ManaPHP\Db::FETCH_ASSOC); print_r($robot);
public fetchOne ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : array | false
$sql string
$bind array
$fetchMode integer
리턴 array | false

getBind() 공개 메소드

Active SQL statement in the object
public getBind ( ) : array
리턴 array

getEmulatedSQL() 공개 메소드

Active SQL statement in the object with replace the bind with value
public getEmulatedSQL ( integer $preservedStrLength ) : string
$preservedStrLength integer
리턴 string

getSQL() 공개 메소드

Active SQL statement in the object
public getSQL ( ) : string
리턴 string

insert() 공개 메소드

Inserts data into a table using custom SQL syntax Inserting a new robot $success = $connection->insert( "robots", array("Boy", 1952), array("name", "year") ); Next SQL sentence is sent to the database system INSERT INTO robots (name, year) VALUES ("boy", 1952);
public insert ( string $table, array $columnValues ) : void
$table string
$columnValues array
리턴 void

isUnderTransaction() 공개 메소드

Checks whether the connection is under a transaction $connection->begin(); var_dump($connection->isUnderTransaction()); //true
public isUnderTransaction ( ) : boolean
리턴 boolean

lastInsertId() 공개 메소드

Returns insert id for the auto_increment column inserted in the last SQL statement
public lastInsertId ( ) : integer
리턴 integer

limit() 공개 메소드

Appends a LIMIT clause to $sqlQuery argument echo $connection->limit("SELECT * FROM robots", 5);
public limit ( string $sql, integer $number, integer $offset ) : string
$sql string
$number integer
$offset integer
리턴 string

query() 공개 메소드

Use this method only when the SQL statement sent to the server is returning rows Querying data $resultset = $connection->query("SELECT * FROM robots WHERE type='mechanical'"); $resultset = $connection->query("SELECT * FROM robots WHERE type=?", array("mechanical"));
public query ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : PdoStatement
$sql string
$bind array
$fetchMode integer
리턴 PdoStatement

rollback() 공개 메소드

Rollbacks the active transaction in the connection
public rollback ( ) : void
리턴 void

update() 공개 메소드

Updates data on a table using custom SQL syntax Updating existing robot $success = $connection->update( "robots", array("name"), array("New Boy"), "id = 101" ); Next SQL sentence is sent to the database system UPDATE robots SET name = "boy" WHERE id = 101
public update ( string $table, array $columnValues, string | array $conditions, array $bind = [] ) : integer
$table string
$columnValues array
$conditions string | array
$bind array
리턴 integer

프로퍼티 상세

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

Last affected rows
protected int $_affectedRows
리턴 integer

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

Active SQL bound parameter variables
protected array $_bind
리턴 array

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

protected string $_dsn
리턴 string

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

protected array $_options
리턴 array

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

protected string $_password
리턴 string

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

protected PDO $_pdo
리턴 PDO

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

Active SQL Statement
protected string $_sql
리턴 string

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

Current transaction level
protected int $_transactionLevel
리턴 integer

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

Type of database system driver is used for
protected string $_type
리턴 string

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

protected string $_username
리턴 string