bit-kitchen/zsql-multiplex

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v0.2.0) of this package.

v0.2.0 2016-08-19 22:58 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:52:41 UTC


README

Build Status

A drop in replacement for zsql\Database with support for read/write splitting.

Usage

$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();