Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.52 KB

readme.md

File metadata and controls

59 lines (41 loc) · 1.52 KB

FluentPDO

FluentPDO - smart SQL builder for PHP.

FluentPDO is small PHP library for rapid query building. Killer feature is "Smart join builder" which generates joins automatically.

Features

  • Fluent interface for creating queries step by step
  • Smart join builder
  • Simple API based on PDO and SQL syntax
  • Build SELECT, INSERT query (UPDATE and DELETE comming soon)
  • Small and fast
  • Type hinting with code completion in smart IDEs
  • requires PHP 5.1+ with any database supported by PDO

Install

Just copy /FluentPDO directory into your libs/ directory then:

include "libs/FluentPDO/FluentPDO.php";
$pdo = new PDO("mysql:dbname=fblog", "root");
$fpdo = new FluentPDO($pdo);

First example

FluentPDO is easy to use:

$query = $fpdo->from('article')
			->where('published_at > ?', $date)
			->orderBy('published_at DESC')
			->limit(5);
if ($user_id) {
	$query = $query
			->where('user_id', $user_id)
			->select('user.name');        // this join table user
}
foreach ($query as $row) {
	echo "$row[name] - $row[title]\n";
}

And executed query is:

SELECT article.*, user.name
FROM article
		LEFT JOIN user ON user.id = article.user_id
WHERE published_at > ? AND user_id = ?
ORDER BY published_at DESC
LIMIT 5

Full documentation can you find on FluentPDO homepage

Licence

Free for commercial and non-commercial use (Apache License or GPL).

Copyright (c) 2012, Marek Lichtner