PHP code example of castroitalo / echoquery

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

    

castroitalo / echoquery example snippets


// Importing library
use CastroItalo\EchoQuery\Builder;

// Instanciate class
$echo_query = new Builder();
$query = $echo_query->select(
    ['column_one', 'co'],
    ['column_two']
)
    ->from('table_one', 'to')
    ->where('column_one')
    ->equalsTo(2)
    ->and('column_two')
    ->equalsTo(5)
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['column_one']
)
    ->from('table_one')
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['*']
)
    ->from('table_one')
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['column_one', 'co'],
    ['column_two', 'ct'],
    ['column_three', 'ctr']
)
    ->from('table_one')
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['column_one', 'co'],
    ['column_two', 'ct'],
    ['column_three', 'ctr']
)
    ->from('table_one')
    ->where('column_on')
    ->greaterThan(10)
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['a.column_one', 'co'],
    ['b.column_two', 'ct'],
)
    ->from('table_one', 'a')
    ->where('column_one')
    ->greaterThan(10)
    ->innerJoin(
        ['table_two', 'b'],
        ['a.column_one', 'b.column_one']
    )
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$sub_query = (new Builder())->select(
    ['a.column_one', 'co'],
    ['b.column_two', 'ct'],
)
    ->from('table_one', 'a')
    ->where('column_one')
    ->getQuery();
$query = (new Builder())->select(
    ['a.column_one', 'co'],
    ['b.column_two', 'ct'],
)
    ->from('table_one', 'a')
    ->where('column_one')
    ->greaterThan(10)
    ->innerJoin(
        [$sub_query, 'b'],
        ['a.column_one', 'b.column_one']
    )
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$union_query = (new Builder())->select(
    ['column_four', 'cfr'],
    ['column_five', 'cf'],
    ['column_six', 'cs']
)
    ->from('table_two', 'tt')
    ->where('column_five')
    ->notIn([1, 3, 4, 6])
    ->getQuery();
$query = (new Builder())->select(
    ['column_one', 'co'],
    ['column_two', 'ct'],
    ['column_three', 'ctr']
)
    ->from('table_one', 'to')
    ->where('column_one')
    ->greaterThan(10)
    ->union($union_query)
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['COUNT(column_one)', 'co'],
    ['SUM(column_two)', 'ct']
)
    ->from('table_one', 'to')
    ->groupBy('column_one', 'column_two')
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['column_one', 'co'],
    ['column_two', 'ct']
)
    ->from('table_one', 'to')
    ->orderBy(
        ['column_one'],
        ['column_two', 'desc']
    )
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['COUNT(column_one)', 'co'],
    ['column_two', 'ct'],
    ['column_three', 'ctr']
)
    ->from('table_one', 'to')
    ->where('column_one')
    ->greaterThan(10)
    ->having('COUNT(column_one)')
    ->greaterThan(10)
    ->getQuery();

use CastroItalo\EchoQuery\Builder;

$query = (new Builder())->select(
    ['COUNT(column_one)', 'co'],
    ['column_two', 'ct'],
)
    ->from('table_one', 'to')
    ->where('column_one')
    ->pagination(10)
    ->getQuery();