/** * Delete from table. * * @param string $table * @param string $where * @param array $bind * @return int Number of affected rows */ public function delete($table, $where = '', array $bind = array()) { $table = $this->adapter->quoteIdentifier($table); $sql = "DELETE FROM {$table}" . ($where ? " WHERE {$where}" : ''); $stmt = $this->adapter->query($sql, $bind); return $stmt->rowCount(); }
/** * @expectedException \Phlib\Db\Exception\RuntimeException */ public function testQueryFailsAfterSuccessfulReconnect() { $exception = new \PDOException('MySQL server has gone away'); $statement = $this->getMock(\PDOStatement::class); $statement->expects($this->any())->method('execute')->will($this->throwException($exception)); $this->pdo->expects($this->any())->method('prepare')->will($this->returnValue($statement)); $adapter = new Adapter(); $adapter->setConnection($this->pdo); $adapter->setConnectionFactory(function () { $exception = new \PDOException('failed for some random reason', 1234); $statement = $this->getMock(\PDOStatement::class); $statement->expects($this->any())->method('execute')->will($this->throwException($exception)); $pdo = $this->getMock('\\Phlib\\Db\\Tests\\PdoMock'); $pdo->expects($this->any())->method('prepare')->will($this->returnValue($statement)); return $pdo; }); $adapter->query('SELECT * FROM foo'); }
/** * @return array */ public function getPlan() { return $this->adapter->query("EXPLAIN {$this->select}", $this->bind)->fetchAll(\PDO::FETCH_ASSOC); }