PHP code example of yesccx / laravel-db-query

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

    

yesccx / laravel-db-query example snippets

 shell
> php artisan vendor:publish --tag=db-query-config
 php
use Yesccx\DBQuery\DBQuery;

$data = DBQuery::connection([
        'driver' => 'mysql',
        'host' => '127.0.0.1'
        'username' => 'example',
        'password' => 'example',
        // ...
    ])
    ->statement('select * from users where id = 1')
    ->get();
 php


namespace App\Services;

use Yesccx\DBQuery\Supports\DBQueryService;

class PatientQueryService extends DBQueryService
{
    /**
     * Define connection config
     *
     * @return string|array connection name or connection config
     */
    protected function connection(): string|array
    {
        return 'mysql';
    }

    public function getList(): array
    {
        return $this->statement('select * from users where type = 1')
            ->get()
            ->toArray();
    }

    public function getUserInfo(int $id): mixed
    {
        return $this->statement('select * from users where @WHERE@')
            ->where('id', $id)
            ->cache(60)
            ->first();
    }

    public function getUserCount(): int
    {
        return $this->statement('select count(*) as count from users')
            ->cache(60)
            ->value('count', 0);
    }
}