crutch / database-pdo
database PDO implementation
v1.0.0
2023-01-19 11:46 UTC
Requires
- php: ^7.4 || ^8.0
- ext-pdo: *
- crutch/database: ^1.0
Provides
This package is not auto-updated.
Last update: 2024-12-19 23:51:45 UTC
README
Database PDO implementation
Install
composer require crutch/database-pdo
Usage
<?php /** @var \PDO $pdo */ $database = new \Crutch\DatabasePdo\DatabasePdo($pdo); $database->execute('INSERT INTO table (id, value) VALUES (?, ?)', [1, 'it is works']); $query = 'SELECT * FROM table WHERE id = ?'; $oneRow = $database->fetch($query, [1]); // $oneRow = ['id' => 1, 'value' => 'it is works']; $allRows = $database->fetchAll($query, [1]); // $allRows = [['id' => 1, 'value' => 'it is works']]; $database->begin(); try { $database->execute('DELETE FROM table WHERE id = :id', ['id' => 1]); $database->commit(); } catch (\Crutch\Database\Exception\StorageError $exception) { $database->rollback(); }