PHP code example of walnut / lib_dbquerybuilder

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

    

walnut / lib_dbquerybuilder example snippets


$quoter = new MysqlQuoter;

$queryFilter = new QueryFilter(
    new AndExpression(
        new OrExpression(
            new NotExpression(
                new FieldExpression('name', 'LIKE',
                    new SqlValue("%test%"))
            ),
            new FieldExpression('id', '>', new SqlValue(3))
        ),
        new RawExpression("`name` NOT IN ('admin', 'dev')"),
        new FieldExpression('name', '!=', 'id')
    )
);

$iqb = new InsertQuery(
    "clients", [
        "id" => new SqlValue(7),
        "name" => new SqlValue('Client 7')
    ]
);
echo $iqb->build($quoter), PHP_EOL;

$uqb = new UpdateQuery(
    "clients", [
        "id" => new PreparedValue('id'),
        "name" => new SqlValue('Client 7')
    ],
    $queryFilter
);
echo $uqb->build($quoter), PHP_EOL;

$sqb = new SelectQuery(
    "clients", [
        "id" => "id",
        "clientName" => "name"
    ],
    [
        new TableJoin("p", "projects", new QueryFilter(
            FieldExpression::equals(
                new TableField("_", "id"),
                new TableField("p", "client_id"),
            )
        ))
    ],
    $queryFilter,
    [
        OrderBy::ascending('id'),
        OrderBy::descending('name')
    ],
    SelectLimit::forPage(3, 20)
);
echo $sqb->build($quoter), PHP_EOL;

$dqb = new DeleteQuery(
    "clients", $qf
);
echo $dqb->build($quoter), PHP_EOL;