pdo

优质
小牛编辑
127浏览
2023-12-01

PDO Object

Medoo是一个基于PDO的项目.你通过 $database->pdo, 能够使用更多的PDO方法, 预定义,事务 , 回滚 等.
更多关于 PDO 的使用, 请阅读: 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 mistake and roll back changes */$database->pdo->rollBack();

Prepare

有时候Medoo不能处理一些复杂的PDO时,你可以使用它来完成.
$calories = 150;$colour = 'red';$sth = $database->pdo->prepare('SELECT name, colour, calories    FROM fruit    WHERE calories bindParam(':calories', $calories, PDO::PARAM_INT);$sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12);$sth->execute();
>