PHP code example of siriusphp / sql

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

    

siriusphp / sql example snippets


use Atlas\Pdo\Connection;
use Sirius\Sql\Select;
use Sirius\Sql\ConditionsEnum;

$connection = Connection::new('sqlite::memory:');
$select = new Select($connection);

// find the 10 "cool" posts that are published and also retrieve the comments count
$select->distinct()
    ->columns('posts.*', 'COUNT(comments.id) AS comments_count')
    ->from('posts')
    ->join('LEFT', 'comments', 'comments.commentable_id = posts.id AND comments.commentable_type = %s', 'posts')
    ->where('posts.published_at < NOW()')
    ->where('posts.title', 'cool', ConditionsEnum::CONTAINS)
    ->groupBy('posts.id')
    ->limit(10);

$posts = $select->fectchAll();