https://github.com/4d47/pdo2
PDO supplements
https://github.com/4d47/pdo2
database php wrapper
Last synced: about 1 month ago
JSON representation
PDO supplements
- Host: GitHub
- URL: https://github.com/4d47/pdo2
- Owner: 4d47
- Created: 2013-11-04T10:33:44.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-04-11T13:12:16.000Z (about 9 years ago)
- Last Synced: 2025-02-04T13:48:57.407Z (3 months ago)
- Topics: database, php, wrapper
- Language: PHP
- Homepage:
- Size: 53.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# PDO2
Lightweight (5.6KB) [PDO](http://php.net/pdo) wrapper to accelerate database development.
## Usage
```php
$db = new PDO2($yourPdoInstance)
```All PDO methods are still available directly,
but the instance is augmented with six extra methods.1. **execute**(string $statement, array $input_parameters = []) : [PDOStatement](http://php.net/manual/en/class.pdostatement.php)
```php
$stm = $db->execute("SELECT * FROM wat WHERE id = ?", [12]);
// shortcut of
$stm = $this->prepare("SELECT * FROM wat WHERE id = ?");
$stm->execute([12]);
```2. **select**($table, $params = [], $extra = '', $values = []) : [PDOStatement](http://php.net/manual/en/class.pdostatement.php)
```php
$db->select('actors');
$db->select('actors', ['first_name' => 'Al']);
$db->select('actors', ['age > ?' => 52]);
$db->select('id,age,name from actors', ['age > ?' => 52]);
// Associative array creates AND, list array creates OR.
$db->select('actors', ['a' => 1, [['b' => 2], ['c' => 3]]])
// SELECT * FROM actors WHERE a = ? AND ((b = ?) OR (c = ?))
```3. **insert**($table, array $params) : [PDOStatement](http://php.net/manual/en/class.pdostatement.php)
```php
$db->insert('actors', ['first_name' => 'Humphrey', 'last_name' => 'Bogart', 'age' => 57]);
```4. **update**($table, array $params, array $where) : [PDOStatement](http://php.net/manual/en/class.pdostatement.php)
```php
$db->update('actors', ['first_name' => 'Tommy'], ['id' => 3])
```5. **delete**($table, array $params) : [PDOStatement](http://php.net/manual/en/class.pdostatement.php)
```php
$db->delete('actors', ['id' => 3]);
$db->delete('actors', []); // empty where part cannot be omitted.
```6. **count**($table, array $params = null) : int
```php
$db->count('actors', ['first_name' => 'Tom'])
```