Executes given SQL statement.
protected _execute ( string $sql, array $params = [], array $prepareOptions = [] ) : mixed | ||
$sql | string | SQL statement |
$params | array | list of params to be bound to query |
$prepareOptions | array | Options to be used in the prepare statement |
return | mixed | PDOStatement if query executes with no problem, true as the result of a successful, false on error query returning no rows, such as a CREATE statement, false otherwise |
/** * Executes given SQL statement. * * @param string $sql SQL statement * @param array $params list of params to be bound to query (supported only in select) * @param array $prepareOptions Options to be used in the prepare statement * @return mixed PDOStatement if query executes with no problem, true as the result of a succesfull, false on error * query returning no rows, suchs as a CREATE statement, false otherwise */ protected function _execute($sql, $params = array(), $prepareOptions = array()) { $this->_lastAffected = false; if (strncasecmp($sql, 'SELECT', 6) == 0) { $prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL); return parent::_execute($sql, $params, $prepareOptions); } try { $this->_lastAffected = $this->_connection->exec($sql); if ($this->_lastAffected === false) { $this->_results = null; $error = $this->_connection->errorInfo(); $this->error = $error[2]; return false; } return true; } catch (PDOException $e) { if (isset($query->queryString)) { $e->queryString = $query->queryString; } else { $e->queryString = $sql; } throw $e; } }
/** * Executes given SQL statement. * * @param string $sql SQL statement * @param array $params list of params to be bound to query (supported only in select) * @param array $prepareOptions Options to be used in the prepare statement * @return mixed PDOStatement if query executes with no problem, true as the result of a successful, false on error * query returning no rows, such as a CREATE statement, false otherwise * @throws PDOException */ protected function _execute($sql, $params = array(), $prepareOptions = array()) { $this->_lastAffected = false; if (strncasecmp($sql, 'SELECT', 6) === 0 || preg_match('/^EXEC(?:UTE)?\\s/mi', $sql) > 0) { return parent::_execute($sql, $params); } try { $this->_lastAffected = $this->_connection->exec($sql); if ($this->_lastAffected === false) { $this->_results = null; $error = $this->_connection->errorInfo(); $this->error = $error[2]; return false; } return true; } catch (PDOException $e) { if (isset($query->queryString)) { $e->queryString = $query->queryString; } else { $e->queryString = $sql; } throw $e; } }
/** * Executes given SQL statement. * * @param string $sql SQL statement * @param array $params list of params to be bound to query (supported only in select) * @param array $prepareOptions Options to be used in the prepare statement * * @return mixed PDOStatement if query executes with no problem, true as the result of a successful, false on error * query returning no rows, such as a CREATE statement, false otherwise * @throws PDOException */ protected function _execute($sql, $params = array(), $prepareOptions = array()) { $this->_lastAffected = FALSE; $sql = trim($sql); if (strncasecmp($sql, 'SELECT', 6) === 0 || preg_match('/^EXEC(?:UTE)?\\s/mi', $sql) > 0) { $prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL); return parent::_execute($sql, $params, $prepareOptions); } try { $this->_lastAffected = $this->_connection->exec($sql); if ($this->_lastAffected === FALSE) { $this->_results = NULL; $error = $this->_connection->errorInfo(); $this->error = $error[2]; return FALSE; } return TRUE; } catch (PDOException $e) { if (isset($query->queryString)) { $e->queryString = $query->queryString; } else { $e->queryString = $sql; } throw $e; } }