PHP code example of vitexsoftware / fluentpdo

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

    

vitexsoftware / fluentpdo example snippets



declare(strict_types=1);

use Envms\FluentPDO\Query;

$pdo = new PDO('mysql:dbname=fluentdb', 'user', 'password');
$fluent = new Query($pdo);

$query = $fluent->from('comment')
             ->where('article.published_at > ?', $date)
             ->orderBy('published_at DESC')
             ->limit(5);

foreach ($query as $row) {
    echo "$row['title']\n";
}

$query = $fluent->from('article')
             ->leftJoin('user ON user.id = article.user_id')
             ->select('user.name');

$query = $fluent->from('article')
             ->leftJoin('user')
             ->select('user.name');

$query = $fluent->from('article')
             ->select('user.name');

$fluent->close();

$query = $fluent->from('article')->where('id', 1)->fetch();
$query = $fluent->from('user', 1)->fetch(); // shorter version if selecting one row by primary key

$values = array('title' => 'article 1', 'content' => 'content 1');

$query = $fluent->insertInto('article')->values($values)->execute();
$query = $fluent->insertInto('article', $values)->execute(); // shorter version

use Envms\FluentPDO\Literal;

$set = ['published_at' => new Literal('NOW()')];

$query = $fluent->update('article')->set($set)->where('id', 1)->execute();
$query = $fluent->update('article', $set, 1)->execute(); // shorter version if updating one row by primary key

$query = $fluent->deleteFrom('article')->where('id', 1)->execute();
$query = $fluent->deleteFrom('article', 1)->execute(); // shorter version if deleting one row by primary key

// Arrays are automatically converted to JSON
$data = [
    'name' => 'John Doe',
    'tags' => ['php', 'mysql', 'programming'],  // Automatically converts to JSON
    'metadata' => ['created' => '2025-01-01', 'active' => true]
];

$fluent->insertInto('users', $data)->execute();


declare(strict_types=1);

// Your code here...