Skip to content

rawb1t/XQuery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

XQuery

Simple Class to build MySQL Queries. The library is using PDO to connect to databases.

Turn code like this:

pdo = new PDO("mysql:host=localhost;port=3306;dbname=database;charset=utf-8", "root", "password");

$stmt = $pdo->prepare("SELECT t1.id, t1.value, DATE_FORMAT(t1.date, '%d.%m.%Y') AS date_formatted, t2.external FROM table1 AS t1 LEFT JOIN table2 AS t2 USING (id) WHERE name LIKE ':query' ORDER BY date DESC LIMIT 5");
$stmt->bindValue(':query', 'foobar');
$stmt->execute();

Into this:

use XQuery\DB;

DB::init("localhost", "root", "password", "database");

$stmt = DB::select( "t1.id", "t1.value", ["DATE_FORMAT(t1.date, '%d.%m.%Y')", "date"], "t2.external" )
->from( "table1", "t1")
->left_join( "table2", "t2" )
->using( "id" )
->where("name LIKE ':query'")
->order( "date DESC" )
->limit(5)
->prepare();

$stmt->bindValue(':query', 'foobar');
$stmt->execute();

About

Simple Class to build MySQL Queries

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages