PHP code example of moitran / package-presto-query-builder-php

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

    

moitran / package-presto-query-builder-php example snippets


        $query = new MoiTran\PrestoQueryBuilder\Query();
        $queryStr = $query->select('*')
           ->from('table1')
           ->whereAnd('col1', 'IS', NULL)
           ->whereAnd('col2', '=', 'value2')
           ->whereOr('col3', 'LIKE', '%test%')
           ->orderBy('col1', 'DESC')
           ->orderBy('col2', 'ASC')
           ->limit(10)
           ->getQueryStr();
    

        $whereAndGroup = new MoiTran\PrestoQueryBuilder\WhereGroup();
        $whereAndGroup->whereAnd('col4', '!=', 'value4');
        $whereAndGroup->whereOr('col5', 'NOT LIKE', 'value5%');
    
        $whereOrGroup = new MoiTran\PrestoQueryBuilder\WhereGroup();
        $whereOrGroup->whereAnd('col6', '=', 'value6');
        $whereOrGroup->whereOr('col7', 'IN', ['value7', 'value8']);
    
        $query = new MoiTran\PrestoQueryBuilder\Query();
        $queryStr = $query->select([
            'col1',
            'col2' => 'colalias2',
            'col3' => 'colalias3'
        ])
            ->from('table1')
            ->whereAnd('col1', 'IS', NULL)
            ->whereAnd('col2', '=', 'value2')
            ->whereOr('col3', 'LIKE', '%test%')
            ->whereAndGroup($whereAndGroup)
            ->whereOrGroup($whereOrGroup)
            ->groupBy(['col1', 'col2', 'col3'])
            ->orderBy('col1', 'DESC')
            ->orderBy('col2', 'ASC')
            ->limit(10)
            ->getQueryStr();
    

        $query = new MoiTran\PrestoQueryBuilder\Query();
        $queryStr = $query->select([
            'a.col1' => 'acol1',
            'a.col2' => 'acol2',
            'b.col1' => 'bcol1',
            'b.col2' => 'bcol2',
        ])
            ->from('table1', 'a')
            ->leftJoin('table2', 'b')
            ->on('a.id', '=', 'b.a_id')
            ->whereAnd('a.col1', '=', 'value1')
            ->limit(10)
            ->getQueryStr();