Easy to use and framework independant fluent database abstraction layer on top of PDO.
FluentDbal is an easy to use and framework independant fluent database abstraction layer on top of PDO. It helps you to structure database queries easly without creating overhead.
- Allows reusing prepared statements
- Promotes use of prepared statements, preventing SQL injection hacks
- Make sure PHP 5.3.* is installed
- Install FluentDbal using Composer or manually
- Create a PDO instance
- Create instance of FluentDbal
- Use FluentDbal to create queries (sharing PDO connection)
$pdo = new \PDO('mysql:host=127.0.0.1;dbname=world', '', ''); $dbal = new FluentDbal($pdo); $query = $dbal ->newQuery() ->select('city.Name,country.name, city.District') ->from('city') ->leftJoin('country', 'country.Code = city.CountryCode') ->where('city.CountryCode = ?', 'NLD') // Orderby can be repeated ->orderby('city.Population','DESC') ->orderby('city.Name','ASC') ->limit(1); $city = $query->execute(); print_r($city->fetch()); // stdClass Object // ( // [Name] => Amsterdam // [name] => Netherlands // [District] => Noord-Holland // )
11-09-2013: Allow usage of named parameters while building query For the functions custom, set, where it is now posible to directly add named parameters, to use this add just one parameter of the type array, with the key as parameter name. If you need to set multiple parameters add this in the same array. It is NOT posible to mix numbered and named parameters.
->where('city.CountryCode = :cc', array(':cc' => 'NLD'))
Copyright (c) 2013 Elze Kool email@example.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.