statement = $statement; $this->conn = $conn; return $this; } public function getQueryString() { return $this->statement->getQueryString(); } public function execute($params = array()) { try { return $this->statement->execute($params); } catch (\Exception $e) { $unreachable = ($e->getCode() === 2006) || (false !== strpos($e->getMessage(), 'MySQL server has gone away')) || (false !== strpos($e->getMessage(), 'errno=32 Broken pipe')); if (!$unreachable) { throw $e; } $this->conn->connect(); } // retry query with update statement $this->statement = $this->conn->prepare($this->getQueryString()); return $this->statement->execute($params); } public function __call($function_name, $parameters) { return call_user_func_array(array($this->statement, $function_name), $parameters); } }