PHP code example of luisaedev / query-builder

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

    

luisaedev / query-builder example snippets


$users = $query
	->select('*', 'users')
	->match('status', 1)
	->limit(10)
	->fetchAll();

$query->select([
	'DATE_FORMAT(co.order_date, "%Y-%m-%d")' => 'order_day',
	'COUNT(DISTINCT co.order_id)'.           => 'num_orders',
	'COUNT(ol.book_id)'.                     => 'num_books'
])
	->from('cust_order co', [
	  'INNER JOIN' => ['order_line ol', 'co.order_id = ol.order_id']
	])
	->groupBy('DATE_FORMAT(co.order_date), "%Y-%m-%d")')
	->orderBy('co.order_date ASC');

composer 

use LuisaeDev\QueryBuilder\QueryBuilder;

// Example of usage with mandatory connection data values
$query = new QueryBuilder([
	'dbname'   => 'test',
	'user'     => 'root',
	'password' => ''
]);

use LuisaeDev\QueryBuilder\QueryBuilder;

// Example of usage with all connection data values allowed and $throws argument to prevent/allow throws PDOException
$query = new QueryBuilder([
	'dbname'       => 'test',
	'user'         => 'root',
	'password'     => '',
	'driver'       => 'mysql',
	'host'         => '127.0.0.1',
	'port'         => '3306',
	'dsn-template' => '$driver:host=$host;port=$port;dbname=$dbname;charset=utf8'
], true);