PHP code example of karlpatrickespiritu / simple-php-pdo-wrapper

1. Go to this page and download the library: Download karlpatrickespiritu/simple-php-pdo-wrapper 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/ */

    

karlpatrickespiritu / simple-php-pdo-wrapper example snippets


use PDO\DB;

$singleRow = DB::i()->fetch('SELECT * FROM `users` WHERE `name` = :name', ['name' => 'Justin Beiber']);

$multipleRows = DB::i()->fetchRows('SELECT * FROM `users`');

$multipleRows = DB::i()->fetchRows('SELECT * FROM `users`');

$rows = DB::i()->getRowCount(); // get the number of rows returned

$columns = DB::i()->getColumnCount(); // get the number of columns per row

var_dump($multipleRows);
var_dump($rows);
var_dump($columns);

$params = [
    ':address' => 'Urgello St., Cebu City, 6000, Cebu',
    ':name' => 'Karl Espiritu',
    ':email' => '[email protected]'
];

DB::i()->exec("INSERT INTO `users`(`name`, `address`, `email`) VALUES (:name, :address, :email)", $params);

var_dump(DB::i()->getLastId()); // dumps the last inserted id

$params = [
    ":name" => "John Mayer",
    ":email" => "[email protected]",
    ":id" => 3
];

$affectedRows = DB::i()->exec("UPDATE `users` SET name = :name, email = :email WHERE id = :id", $params);

var_dump($affectedRows); // dumps the number of affected rows

$affectedRows = DB::i()->exec("DELETE FROM `users` WHERE id = :id", [':id' => 1]);

var_dump($affectedRows); // dumps the number of affected rows
JavaScript


return [
    /**
     * Your database configuration. Modify accordingly.
     *
     * @see http://php.net/manual/en/pdo.construct.php
     */
    'DB_CONFIG' => [
        'host' => 'localhost',
        'port' => '',
        'dbname' => '',
        'username' => 'root',
        'password' => ''
    ],

    /**
     * Default PDO attributes. Modify accordingly.
     *
     * @see http://php.net/manual/en/pdo.setattribute.php
     */
    'PDO_ATTRIBUTES' => [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]
];