Skip to content

Commit

Permalink
Added MySQl\Connection->begin(), commit(), rollback()
Browse files Browse the repository at this point in the history
  • Loading branch information
kakserpom committed Apr 4, 2016
1 parent 26959a6 commit 66bfd9c
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions PHPDaemon/Clients/MySQL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,42 +343,71 @@ public function auth() {
/**
* Sends SQL-query
* @param string $q Query
* @param callable $callback Optional. Callback called when response received
* @callback $callback ( Connection $conn, boolean $success )
* @param callable $cb Optional. Callback called when response received
* @callback $cb ( Connection $conn, boolean $success )
* @return boolean Success
*/
public function query($q, $callback = NULL) {
public function query($q, $cb = null) {
if ($this->finished) {
throw new ConnectionFinished;
}
return $this->command(Pool::COM_QUERY, $q, $callback);
return $this->command(Pool::COM_QUERY, $q, $cb);
}

/**
* Begins a transaction
* @param callable $cb Optional. Callback called when response received
* @throws ConnectionFinished
*/
public function begin($cb = null) {
$this->query('BEGIN', $cb);
$this->acquire();
}

/**
* Commit a transaction
* @param callable $cb Optional. Callback called when response received
* @throws ConnectionFinished
*/
public function commit($cb = null) {
$this->query('COMMIT', $cb);
$this->release();
}

/**
* Rollback a transaction
* @throws ConnectionFinished
*/
public function rollback($cb = null) {
$this->query('ROLLBACK', $cb);
$this->release();
}

/**
* Sends echo-request
* @param callable $callback Optional. Callback called when response received
* @callback $callback ( Connection $conn, boolean $success )
* @param callable $cb Optional. Callback called when response received
* @callback $cb ( Connection $conn, boolean $success )
* @return boolean Success
*/
public function ping($callback = NULL) {
return $this->command(Pool::COM_PING, '', $callback);
public function ping($cb = NULL) {
return $this->command(Pool::COM_PING, '', $cb);
}

/**
* Sends arbitrary command
* @param string $cmd Command
* @param string $q Data
* @param callable $callback Optional
* @param callable $cb Optional
* @throws ConnectionFinished
* @callback $callback ( Connection $conn, boolean $success )
* @callback $cb ( Connection $conn, boolean $success )
* @return boolean Success
*/
public function command($cmd, $q = '', $callback = NULL) {
public function command($cmd, $q = '', $cb = NULL) {
if ($this->phase !== self::PHASE_HANDSHAKED) {
return false;
}

$this->onResponse->push($callback);
$this->onResponse->push($cb);
$this->seq = 0;
$this->sendPacket(chr($cmd) . $q);

Expand Down

0 comments on commit 66bfd9c

Please sign in to comment.