Пример #1
0
 /**
  * destructor - rollbacks the active transaction if php script ends prematurely
  * and commit is forgotten to be called
  *
  * also the connection is being closed here
  */
 public function __destruct()
 {
     if ($this->isInTransaction()) {
         $this->rollbackTransaction();
     }
     $this->connection->close();
 }
Пример #2
0
<?php

/*
 * This is a sample for using the PHP Vitess client with VTGateV3.
 *
 * Before running this, start up a local V3 demo cluster by running:
 * vitess/examples/demo$ ./run.py
 *
 * Then in another terminal:
 * vitess/examples/demo$ php client.php --server=localhost:12346
 */
require_once __DIR__ . '/../../php/vendor/autoload.php';
use Vitess\Context;
use Vitess\VTGateConn;
use Vitess\Proto\Topodata\TabletType;
$opts = getopt('', array('server:'));
// Create a connection.
$ctx = Context::getDefault();
$conn = new VTGateConn(new \Vitess\Grpc\Client($opts['server'], ['credentials' => Grpc\ChannelCredentials::createInsecure()]));
// Insert something.
$tx = $conn->begin($ctx);
$tx->execute($ctx, 'INSERT INTO user (name) VALUES (:name)', array('name' => 'sugu'));
$tx->commit($ctx);
// Read it back.
$cursor = $conn->execute($ctx, 'SELECT * FROM user', array(), TabletType::MASTER);
while (($row = $cursor->next()) !== FALSE) {
    print_r($row);
}
$conn->close();