version: 2.1.12
PDO object
Medoo is based on the PDO object. You can access the PDO object directly via using $database->pdo
, so that you can use all PDO methods if you needed, like prepare
, transaction
, rollBack
, or more.
For more information about the PDO class, read more from: http://php.net/manual/en/class.pdo.php.
Transaction
$database->pdo->beginTransaction(); $database->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com", "age" => 25 ]); /* Commit the changes */ $database->pdo->commit(); /* Recognize mistakes and roll back changes */ $database->pdo->rollBack();
Prepared Statement
Sometimes, if Medoo cannot process a complex SQL query, you can use it like a PDO wrapper with PDO internal functions to process the query in case of SQL injection.
$calories = 150; $colour = 'red'; $sth = $database->pdo->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute();