crutch/database-pdo

database PDO implementation

v1.0.0 2023-01-19 11:46 UTC

This package is not auto-updated.

Last update: 2024-11-21 23:31:53 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();
}