/** * Execute the SQL statement. * * @param boolean $replacePrefixQuotes Replace the prefixes inside the quotes too * * @return mixed A database cursor resource on success, boolean false on failure. * * @since 12.1 * @throws RuntimeException */ public function execute($replacePrefixQuotes = false) { if ($replacePrefixQuotes) { $this->sql = $this->replacePrefix((string) $this->sql, '#__', $replacePrefixQuotes); } return parent::execute(); }
/** * Constructor. * * @param array $options Array of database options with keys: host, user, password, database, select. * * @since 12.1 */ public function __construct($options) { // Get some basic values from the options. $options['host'] = isset($options['host']) ? $options['host'] : 'localhost'; $options['user'] = isset($options['user']) ? $options['user'] : '******'; $options['password'] = isset($options['password']) ? $options['password'] : ''; $options['database'] = isset($options['database']) ? $options['database'] : ''; $options['select'] = isset($options['select']) ? (bool) $options['select'] : true; // Finalize initialisation. parent::__construct($options); }
/** * Constructor. * * @param array $options Array of database options with keys: host, user, password, database, select. * * @since 12.1 */ public function __construct($options) { // PHP's `mysql` extension is not present in PHP 7, block instantiation in this environment if (PHP_MAJOR_VERSION >= 7) { throw new JDatabaseExceptionUnsupported('This driver is unsupported in PHP 7, please use the MySQLi or PDO MySQL driver instead.'); } // Get some basic values from the options. $options['host'] = isset($options['host']) ? $options['host'] : 'localhost'; $options['user'] = isset($options['user']) ? $options['user'] : '******'; $options['password'] = isset($options['password']) ? $options['password'] : ''; $options['database'] = isset($options['database']) ? $options['database'] : ''; $options['select'] = isset($options['select']) ? (bool) $options['select'] : true; // Finalize initialisation. parent::__construct($options); }
/** * Test isSupported method. * * @return void * * @since 11.4 */ public function testIsSupported() { $this->assertThat(JDatabaseDriverMysqli::isSupported(), $this->isTrue(), __LINE__); }
/** * Method to return a JDatabaseDriver instance based on the given options. There are three global options and then * the rest are specific to the database driver. The 'driver' option defines which JDatabaseDriver class is * used for the connection -- the default is 'mysqli'. The 'database' option determines which database is to * be used for the connection. The 'select' option determines whether the connector should automatically select * the chosen database. * * Instances are unique to the given options and new objects are only created when a unique options array is * passed into the method. This ensures that we don't end up with unnecessary database connection resources. * * @param array $options Parameters to be passed to the database driver. * * @return JDatabaseDriver A database object. * * @since 11.1 * @throws RuntimeException */ public static function getInstance($options = array()) { // Sanitize the database connector options. $options['driver'] = isset($options['driver']) ? preg_replace('/[^A-Z0-9_\\.-]/i', '', $options['driver']) : 'mysqli'; $options['database'] = isset($options['database']) ? $options['database'] : null; $options['select'] = isset($options['select']) ? $options['select'] : true; // If the selected driver is `mysql` and we are on PHP 7 or greater, switch to the `mysqli` driver. if ($options['driver'] == 'mysql' && PHP_MAJOR_VERSION >= 7) { // Check if we have support for the other MySQL drivers $mysqliSupported = JDatabaseDriverMysqli::isSupported(); $pdoMysqlSupported = JDatabaseDriverPdomysql::isSupported(); // If neither is supported, then the user cannot use MySQL; throw an exception if (!$mysqliSupported && !$pdoMysqlSupported) { throw new RuntimeException('The PHP `ext/mysql` extension is removed in PHP 7, cannot use the `mysql` driver.' . ' Also, this system does not support MySQLi or PDO MySQL. Cannot instantiate database driver.'); } // Prefer MySQLi as it is a closer replacement for the removed MySQL driver, otherwise use the PDO driver if ($mysqliSupported) { JLog::add('The PHP `ext/mysql` extension is removed in PHP 7, cannot use the `mysql` driver. Trying `mysqli` instead.', JLog::WARNING, 'deprecated'); $options['driver'] = 'mysqli'; } else { JLog::add('The PHP `ext/mysql` extension is removed in PHP 7, cannot use the `mysql` driver. Trying `pdomysql` instead.', JLog::WARNING, 'deprecated'); $options['driver'] = 'pdomysql'; } } // Get the options signature for the database connector. $signature = md5(serialize($options)); // If we already have a database connector instance for these options then just use that. if (empty(self::$instances[$signature])) { // Derive the class name from the driver. $class = 'JDatabaseDriver' . ucfirst(strtolower($options['driver'])); // If the class still doesn't exist we have nothing left to do but throw an exception. We did our best. if (!class_exists($class)) { throw new RuntimeException(sprintf('Unable to load Database Driver: %s', $options['driver'])); } // Create our new JDatabaseDriver connector based on the options given. try { $instance = new $class($options); } catch (RuntimeException $e) { throw new RuntimeException(sprintf('Unable to connect to the Database: %s', $e->getMessage()), $e->getCode(), $e); } // Set the new connector to the global instances based on signature. self::$instances[$signature] = $instance; } return self::$instances[$signature]; }
/** * Load an array using the first column of the query * * @return array */ public function loadArray() { /** @noinspection PhpUndefinedClassInspection */ $list = parent::loadRowList(); $array = array(); foreach ($list as $listElement) { $array[] = $listElement[0]; } return $array; }