| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Db\Adapter; |
|
|
| use Exception; |
| use Piwik\Config; |
| use Piwik\Db; |
| use Piwik\Db\AdapterInterface; |
| use Piwik\Db\Schema; |
| use Piwik\Piwik; |
| use Zend_Config; |
| use Zend_Db_Adapter_Mysqli; |
|
|
| class Mysqli extends Zend_Db_Adapter_Mysqli implements AdapterInterface |
| { |
| use Db\TransactionalDatabaseDynamicTrait; |
|
|
| |
| |
| |
| public function __construct($config) |
| { |
| |
| $config['driver_options'][MYSQLI_OPT_LOCAL_INFILE] = true; |
|
|
| if ($config['enable_ssl']) { |
| if (!empty($config['ssl_key'])) { |
| $config['driver_options']['ssl_key'] = $config['ssl_key']; |
| } |
| if (!empty($config['ssl_cert'])) { |
| $config['driver_options']['ssl_cert'] = $config['ssl_cert']; |
| } |
| if (!empty($config['ssl_ca'])) { |
| $config['driver_options']['ssl_ca'] = $config['ssl_ca']; |
| } |
| if (!empty($config['ssl_ca_path'])) { |
| $config['driver_options']['ssl_ca_path'] = $config['ssl_ca_path']; |
| } |
| if (!empty($config['ssl_cipher'])) { |
| $config['driver_options']['ssl_cipher'] = $config['ssl_cipher']; |
| } |
| if (!empty($config['ssl_no_verify'])) { |
| $config['driver_options']['ssl_no_verify'] = $config['ssl_no_verify']; |
| } |
| } |
|
|
| parent::__construct($config); |
| } |
|
|
| |
| |
| |
| public function resetConfig() |
| { |
| $this->_config = array(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public static function getDefaultPort() |
| { |
| return 3306; |
| } |
|
|
| protected function _connect() // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
| { |
| if ($this->_connection) { |
| return; |
| } |
|
|
| |
| |
| |
| mysqli_report(MYSQLI_REPORT_OFF); |
|
|
| parent::_connect(); |
|
|
| $this->_connection->query('SET sql_mode = "' . Db::SQL_MODE . '"'); |
| } |
|
|
| |
| |
| |
| |
| |
| public function checkServerVersion() |
| { |
| $requiredVersion = Schema::getInstance()->getMinimumSupportedVersion(); |
| $serverVersion = $this->getServerVersion(); |
|
|
| if (version_compare($serverVersion, $requiredVersion) === -1) { |
| throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion))); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| public function getServerVersion() |
| { |
| |
| |
| $versionInfo = $this->fetchAll('SELECT @@VERSION'); |
|
|
| if (count($versionInfo)) { |
| return $versionInfo[0]['@@VERSION']; |
| } |
|
|
| return parent::getServerVersion(); |
| } |
|
|
| |
| |
| |
| |
| |
| public function checkClientVersion() |
| { |
| $serverVersion = $this->getServerVersion(); |
| $clientVersion = $this->getClientVersion(); |
|
|
| |
| if ( |
| version_compare($serverVersion, '5.0.3') >= 0 |
| && version_compare($clientVersion, '5.0.3') < 0 |
| ) { |
| throw new Exception(Piwik::translate('General_ExceptionIncompatibleClientServerVersions', array('MySQL', $clientVersion, $serverVersion))); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function rowCount($queryResult) |
| { |
| return mysqli_affected_rows($this->_connection); |
| } |
|
|
| |
| |
| |
| |
| |
| public static function isEnabled() |
| { |
| $extensions = @get_loaded_extensions(); |
| return in_array('mysqli', $extensions); |
| } |
|
|
| |
| |
| |
| |
| |
| public function hasBlobDataType() |
| { |
| return true; |
| } |
|
|
| |
| |
| |
| |
| |
| public function hasBulkLoader() |
| { |
| return true; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function isErrNo($e, $errno) |
| { |
| return self::isMysqliErrorNumber($e, $this->_connection, $errno); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public static function isMysqliErrorNumber($e, $connection, $errno) |
| { |
| if (is_null($connection)) { |
| if (preg_match('/(?:\[|\s)([0-9]{4})(?:\]|\s)/', $e->getMessage(), $match)) { |
| return $match[1] == $errno; |
| } |
| return mysqli_connect_errno() == $errno; |
| } |
|
|
| return mysqli_errno($connection) == $errno; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function exec($sqlQuery) |
| { |
| $rc = mysqli_query($this->_connection, $sqlQuery); |
| $rowsAffected = mysqli_affected_rows($this->_connection); |
| if (!is_bool($rc)) { |
| mysqli_free_result($rc); |
| } |
| return $rowsAffected; |
| } |
|
|
|
|
| |
| |
| |
| |
| |
| public function getClientVersion() |
| { |
| $this->_connect(); |
|
|
| $version = $this->_connection->server_version; |
| $major = (int)($version / 10000); |
| $minor = (int)($version % 10000 / 100); |
| $revision = (int)($version % 100); |
|
|
| return $major . '.' . $minor . '.' . $revision; |
| } |
| } |
|
|