PHP code example of advmaker / fluentpdo

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

    

advmaker / fluentpdo example snippets




$pdo = new PDO("mysql:dbname=fblog", "root");
$fpdo = new FluentPDO($pdo);

$query = $fpdo->from('article')
            ->where('published_at > ?', $date)
            ->orderBy('published_at DESC')
            ->limit(5);
foreach ($query as $row) {
    echo "$row[title]\n";
}

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

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

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

$query = $fpdo->from('article')->where('id', 1);
// or shortly if you select one row by primary key
$query = $fpdo->from('user', 1);

$values = array('title' => 'article 1', 'content' => 'content 1');
$query = $fpdo->insertInto('article')->values($values)->execute();
// or shortly
$query = $fpdo->insertInto('article', $values)->execute();

$set = array('published_at' => new FluentLiteral('NOW()'));
$query = $fpdo->update('article')->set($set)->where('id', 1)->execute();
// or shortly if you update one row by primary key
$query = $fpdo->update('article', $set, 1)->execute();

$query = $fpdo->deleteFrom('article')->where('id', 1)->execute();
// or shortly if you delete one row by primary key
$query = $fpdo->deleteFrom('article', 1)->execute();