PHP Interface ManaPHP\DbInterface

Mostra file Open project: manaphp/manaphp

Public Methods

Method Description
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
escapeIdentifier ( string | array $identifier ) : string Escapes a column/table/schema name
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
fetchOne ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : array | false Returns the first row in a SQL query result
getBind ( ) : array Active SQL statement in the object
getEmulatedSQL ( integer $preservedStrLength ) : string Active SQL statement in the object with replace the bind with value
getMetadata ( $source ) : array
getSQL ( ) : string Active SQL statement in the object
insert ( string $table, array $columnValues ) : void Inserts data into a table using custom SQL syntax
isUnderTransaction ( ) : boolean Checks whether the connection is under a transaction
lastInsertId ( ) : integer Returns insert id for the auto_increment column inserted in the last SQL statement
limit ( string $sql, integer $number, integer $offset = null ) : string Appends a LIMIT clause to $sql argument
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
truncateTable ( string $source ) : static
update ( string $table, array $columnValues, string | array $conditions, array $bind = [] ) : integer Updates data on a table using custom SQL syntax

Method Details

affectedRows() public method

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

begin() public method

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

commit() public method

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

delete() public method

$db->delete('_student','id=1'); $db->delete('_student',['id'=>1]); $db->delete('_student',['id'=>1]); $db->delete('_student','id=:id',['id'=>1]);
public delete ( string $table, string | array $conditions, array $bind = [] ) : integer
$table string
$conditions string | array
$bind array
return integer

escapeIdentifier() public method

Escapes a column/table/schema name
public escapeIdentifier ( string | array $identifier ) : string
$identifier string | array
return string

execute() public method

Use this method only when the SQL statement sent to the server don't return any row
public execute ( string $sql, array $bind = [] ) : integer
$sql string
$bind array
return integer

fetchAll() public method

$db->fetchAll('SELECT * FROM city'); $db->fetchAll('SELECT * FROM city WHERE city_id <:city_id',['city_id'=>5]);
public fetchAll ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : array
$sql string
$bind array
$fetchMode integer
return array

fetchOne() public method

$db->fetchOne('SELECT * FROM city'); $db->fetchOne('SELECT * FROM city WHERE city_id =:city_id',['city_id'=>5]);
public fetchOne ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : array | false
$sql string
$bind array
$fetchMode integer
return array | false

getBind() public method

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

getEmulatedSQL() public method

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

getMetadata() public method

public getMetadata ( $source ) : array
return array

getSQL() public method

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

insert() public method

$db->insert('_student',['age'=>30,'name'=>'Mark']); $db->insert('_student',[null,30,'Mark']);
public insert ( string $table, array $columnValues ) : void
$table string
$columnValues array
return void

isUnderTransaction() public method

$connection->begin(); var_dump($connection->isUnderTransaction()); //true
public isUnderTransaction ( ) : boolean
return boolean

lastInsertId() public method

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

limit() public method

$db->limit('',10); //LIMIT 10 $db->limit('',10,100); //LIMIT 10 OFFSET 100
public limit ( string $sql, integer $number, integer $offset = null ) : string
$sql string
$number integer
$offset integer
return string

query() public method

Use this method only when the SQL statement sent to the server return rows
public query ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : PDOStatement
$sql string
$bind array
$fetchMode integer
return PDOStatement

rollback() public method

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

truncateTable() public method

public truncateTable ( string $source ) : static
$source string
return static

update() public method

$db->update('_student',['name'=>'mark'],'id=2'); $db->update('_student',['name'=>'mark'],['id'=>2]); $db->update('_student',['name'=>'mark'],'id=:id',['id'=>2]);
public update ( string $table, array $columnValues, string | array $conditions, array $bind = [] ) : integer
$table string
$columnValues array
$conditions string | array
$bind array
return integer