Getting started

Installation

Phluent can be used as a composer package or a single file download and included into your project.

Using Composer

$ composer require indgy/phluent

Standalone

Use the standalong Phluent.php file in the dist folder which combines Query, DB and the functions files into one.

cp dist/Phluent.php /path/to/your/project

Then require it where needed in your project:

require("/path/to/your/project/Phluent.php");

Creating a PDO connection

DB requires a PDO connection to your database.

$dsn = 'mysql:host=localhost;port=3306;dbname=database;charset=utf8mb4';
$pdo = new \PDO($dsn, 'username', 'password', [
    \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
    \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
    \PDO::ATTR_EMULATE_PREPARES => true,
]);

You can now use DB to perform SQL queries on the database:

$db = new DB($pdo);
$db->query("SELECT * FROM `movies` WHERE `title` LIKE '%Muppets%'");

foreach ($db->get() as $movie) {
  echo "{$movie->title} was released in {$movie->year}";
}

Read the Query guide for more details on generating SQL.

Note

The PDO guide at PHP delusions is a good read.