PHP code example of crankydragon / zsql-multiplex

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

    

crankydragon / zsql-multiplex example snippets


$database = new \zsql\Multiplex($reader, $writer);

// select runs against $reader
$database->select()
  ->from('tableName')
  ->where('columnName', 'value')
  ->limit(1)
  ->query();

// insert runs against $writer
$id = $database->insert()
  ->ignore()
  ->into('tableName')
  ->value('columnName', 'value')
  ->value('otherColumnName', 'otherValue')
  ->query();

// update runs against $writer
$database->update()
  ->table('tableName')
  ->set('columnName', 'value')
  ->set('someColumn', new zsql\Expression('NOW()'))
  ->where('otherColumnName', 'otherValue')
  ->limit(1)
  ->query();

// delete runs against $writer
$database->delete()
  ->from('tableName')
  ->where('columnName', 'value')
  ->limit(1)
  ->query();

// ensure that the next query uses the $writer
$insert   = $database->query('SET @num := 1');
$result   = $database->useWriter()
  ->query('SELECT @num')
  ->fetchColumn();