PHP code example of naga3 / qb

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

    

naga3 / qb example snippets


$rows = Qb('contact')->toJson();



Qb::connect('sqlite:sample.db');
Qb::connect('mysql:host=localhost;dbname=sample', 'user', 'pass');

$rows = Qb('contact')->toJson();

$rows = Qb('contact')->select('name')->select('tel')->toArray();

$rows = Qb('contact')->select(['name', 't' => 'tel'])->toObject();

$row = Qb('contact')->where('id', 1)->oneArray();

$row = Qb('contact')->where(1)->oneArray(); // In the case of id column, it can be omitted column specified
$row = Qb('contact')->oneArray('id', 1);
$row = Qb('contact')->oneArray(1);

$rows = Qb('contact')->whereGte('status', 1)->whereLike('name', '%Yamada%')->toJson();

$rows = Qb('contact')->join('access', 'access.contact_id = contact.id')->toJson();

$rows = Qb('contact')->leftJoin('access', 'access.contact_id = contact.id')->toJson();

$id = Qb('contact')->save(['name' => 'Ichiro Suzuki', 'age' => 19]);

Qb('contact')->where('age', 20)->save(['name' => 'Ichiro Suzuki', 'age' => 19]);

Qb('contact')->where('age', 20)->update(['name' => 'Ichiro Suzuki', 'age' => 19]);

Qb('contact')->where('age', 20)->update('name', 'Ichiro Suzuki');

Qb('contact')->where('age', 20)->set('age', 19)->set('name', 'Ichiro Suzuki')->update();

Qb('contact')->where('age', 20)->delete();

Qb('contact')->delete(1);

$rows = Qb('contact')->asc('created_at')->toJson();

$rows = Qb('contact')->desc('created_at')->asc('id')->toJson();

$rows = Qb('contact')->offset(10)->limit(5)->toJson();

$db = Qb('contact')->db();

$options = [
  // Primary key
  'primary_key' => 'id',
  // ERRMODE
  'error_mode' => PDO::ERRMODE_EXCEPTION,
  // json_encode options
  'json_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT,
];
Qb::connect($dsn, $user, $pass, $options);