PHP code example of solution10 / sql

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

    

solution10 / sql example snippets


$query = (new Solution10\SQL\Select())
    ->select(['users.name', 'locations.name'])
    ->from('users')
    ->join('locations', 'users.location_id', '=', 'locations.id')
    ->where('users.id', '>', 15)
    ->limit(25)
    ->offset(10)
    ->orderBy('name', 'DESC');

// Make use of an existing PDO object to actually run the query:
$stmt = $pdo->prepare((string)$query);
$stmt->execute($query->params());
$rows = $stmt->fetchAll();

$query = (new Solution10\SQL\Insert())
    ->table('users')
    ->values([
        'name' => 'Alex',
        'location_id' => 27
    ]);

// Use with PDO in exactly the same way as SELECT:
$stmt = $pdo->prepare((string)$query);
$stmt->execute($query->params());

$query = (new Solution10\SQL\Update())
    ->table('users')
    ->where('id', '=', 15)
    ->values([
        'name' => 'Alex',
        'location_id' => 27
    ]);

// Use with PDO in exactly the same way as SELECT:
$stmt = $pdo->prepare((string)$query);
$stmt->execute($query->params());

$query = (new Solution10\SQL\Delete())
    ->table('users')
    ->where('id', '=', 27)
    ->limit(1);

// Use with PDO in exactly the same way as SELECT:
$stmt = $pdo->prepare((string)$query);
$stmt->execute($query->params());

$query = (new Solution10\SQL\Select(new Solution10\SQL\Dialect\MySQL()))
    ->select('*')
    ->from('users')
    ->limit(10);