PHP code example of giovanniramos / pdo4you

1. Go to this page and download the library: Download giovanniramos/pdo4you 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/ */

    

giovanniramos / pdo4you example snippets


use PDO;
use PDO4You\PDO4You;
use PDO4You\Platform\MySqlPlatform;

// 1. Create a native PDO connection
$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'user', 'password');

// 2. Select the platform
$platform = new MySqlPlatform();

// 3. Inject into PDO4You
$db = new PDO4You($pdo, $platform);

// SELECT (returns associative array)
$users = $db->select("SELECT * FROM users WHERE status = ?", ['active']);

// EXECUTE (insert, update, delete)
$db->exec("UPDATE users SET status = 'inactive' WHERE id = 1");

// GET LAST ID (using the platform strategy)
$newId = $db->lastId();