Get Started

Upgrade

Where Syntax

Query

Aggregation

Fetch

Transaction

Management

Advanced

Raw object

PDO object

Debug

Information

version: 2.2.0

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

  1. $database->pdo->beginTransaction();
  2.  
  3. $database->insert("account", [
  4. "user_name" => "foo",
  5. "email" => "foo@bar.com",
  6. "age" => 25
  7. ]);
  8.  
  9. /* Commit the changes */
  10. $database->pdo->commit();
  11.  
  12. /* Recognize mistakes and roll back changes */
  13. $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.

  1. $calories = 150;
  2. $colour = 'red';
  3.  
  4. $sth = $database->pdo->prepare('SELECT name, colour, calories
  5. FROM fruit
  6. WHERE calories < :calories AND colour = :colour');
  7.  
  8. $sth->bindParam(':calories', $calories, PDO::PARAM_INT);
  9. $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12);
  10.  
  11. $sth->execute();