PHP code example of 4d47 / pdo2

1. Go to this page and download the library: Download 4d47/pdo2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

4d47 / pdo2 example snippets


$db = new PDO2($yourPdoInstance)

    $stm = $db->execute("SELECT * FROM wat WHERE id = ?", [12]);
    // shortcut of
    $stm = $this->prepare("SELECT * FROM wat WHERE id = ?");
    $stm->execute([12]);
    

    $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 = ?))
    

    $db->insert('actors', ['first_name' => 'Humphrey', 'last_name' => 'Bogart', 'age' => 57]);
    

    $db->update('actors', ['first_name' => 'Tommy'], ['id' => 3])
    

    $db->delete('actors', ['id' => 3]);
    $db->delete('actors', []); // empty where part cannot be omitted.
    

    $db->count('actors', ['first_name' => 'Tom'])