Свойство | Type | Description | |
---|---|---|---|
$_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 |
Méthode | Description | |
---|---|---|
__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
|
Méthode | Description | |
---|---|---|
_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 |
public __construct ( array $options ) | ||
$options | array |
$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 | |
Résultat | PDOStatement |
public affectedRows ( ) : integer | ||
Résultat | integer |
Deleting existing robot
$success = $connection->delete(
"robots",
"id = 101"
);
Next SQL sentence is generated
DELETE FROM robots WHERE id = 101
Inserting data
$success = $connection->execute("INSERT INTO robots VALUES (1, 'Boy')");
$success = $connection->execute("INSERT INTO robots VALUES (?, ?)", array(1, 'Boy'));
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);
}
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 getEmulatedSQL ( integer $preservedStrLength ) : string | ||
$preservedStrLength | integer | |
Résultat | string |
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);
$connection->begin();
var_dump($connection->isUnderTransaction()); //true
public isUnderTransaction ( ) : boolean | ||
Résultat | boolean |
public lastInsertId ( ) : integer | ||
Résultat | integer |
echo $connection->limit("SELECT * FROM robots", 5);
Querying data
$resultset = $connection->query("SELECT * FROM robots WHERE type='mechanical'");
$resultset = $connection->query("SELECT * FROM robots WHERE type=?", array("mechanical"));
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
protected int $_affectedRows | ||
Résultat | integer |
protected array $_bind | ||
Résultat | array |
protected int $_transactionLevel | ||
Résultat | integer |
protected string $_type | ||
Résultat | string |