|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package FrameworkOnFramework |
| 4 | + * @subpackage database |
| 5 | + * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved. |
| 6 | + * @license GNU General Public License version 2 or later; see LICENSE.txt |
| 7 | + * |
| 8 | + * This file is adapted from the Joomla! Platform. It is used to iterate a database cursor returning FOFTable objects |
| 9 | + * instead of plain stdClass objects |
| 10 | + */ |
| 11 | + |
| 12 | +// Protect from unauthorized access |
| 13 | +defined('FOF_INCLUDED') or die; |
| 14 | + |
| 15 | +/** |
| 16 | + * Database connector class. |
| 17 | + * |
| 18 | + * @since 11.1 |
| 19 | + * @deprecated 13.3 (Platform) & 4.0 (CMS) |
| 20 | + */ |
| 21 | +abstract class FOFDatabase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * Execute the SQL statement. |
| 25 | + * |
| 26 | + * @return mixed A database cursor resource on success, boolean false on failure. |
| 27 | + * |
| 28 | + * @since 11.1 |
| 29 | + * @throws RuntimeException |
| 30 | + * @deprecated 13.1 (Platform) & 4.0 (CMS) |
| 31 | + */ |
| 32 | + public function query() |
| 33 | + { |
| 34 | + if (class_exists('JLog')) |
| 35 | + { |
| 36 | + JLog::add('FOFDatabase::query() is deprecated, use FOFDatabaseDriver::execute() instead.', JLog::WARNING, 'deprecated'); |
| 37 | + } |
| 38 | + |
| 39 | + return $this->execute(); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Get a list of available database connectors. The list will only be populated with connectors that both |
| 44 | + * the class exists and the static test method returns true. This gives us the ability to have a multitude |
| 45 | + * of connector classes that are self-aware as to whether or not they are able to be used on a given system. |
| 46 | + * |
| 47 | + * @return array An array of available database connectors. |
| 48 | + * |
| 49 | + * @since 11.1 |
| 50 | + * @deprecated 13.1 (Platform) & 4.0 (CMS) |
| 51 | + */ |
| 52 | + public static function getConnectors() |
| 53 | + { |
| 54 | + if (class_exists('JLog')) |
| 55 | + { |
| 56 | + JLog::add('FOFDatabase::getConnectors() is deprecated, use FOFDatabaseDriver::getConnectors() instead.', JLog::WARNING, 'deprecated'); |
| 57 | + } |
| 58 | + |
| 59 | + return FOFDatabaseDriver::getConnectors(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Gets the error message from the database connection. |
| 64 | + * |
| 65 | + * @param boolean $escaped True to escape the message string for use in JavaScript. |
| 66 | + * |
| 67 | + * @return string The error message for the most recent query. |
| 68 | + * |
| 69 | + * @deprecated 13.3 (Platform) & 4.0 (CMS) |
| 70 | + * @since 11.1 |
| 71 | + */ |
| 72 | + public function getErrorMsg($escaped = false) |
| 73 | + { |
| 74 | + if (class_exists('JLog')) |
| 75 | + { |
| 76 | + JLog::add('FOFDatabase::getErrorMsg() is deprecated, use exception handling instead.', JLog::WARNING, 'deprecated'); |
| 77 | + } |
| 78 | + |
| 79 | + if ($escaped) |
| 80 | + { |
| 81 | + return addslashes($this->errorMsg); |
| 82 | + } |
| 83 | + else |
| 84 | + { |
| 85 | + return $this->errorMsg; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Gets the error number from the database connection. |
| 91 | + * |
| 92 | + * @return integer The error number for the most recent query. |
| 93 | + * |
| 94 | + * @since 11.1 |
| 95 | + * @deprecated 13.3 (Platform) & 4.0 (CMS) |
| 96 | + */ |
| 97 | + public function getErrorNum() |
| 98 | + { |
| 99 | + if (class_exists('JLog')) |
| 100 | + { |
| 101 | + JLog::add('FOFDatabase::getErrorNum() is deprecated, use exception handling instead.', JLog::WARNING, 'deprecated'); |
| 102 | + } |
| 103 | + |
| 104 | + return $this->errorNum; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Method to return a FOFDatabaseDriver instance based on the given options. There are three global options and then |
| 109 | + * the rest are specific to the database driver. The 'driver' option defines which FOFDatabaseDriver class is |
| 110 | + * used for the connection -- the default is 'mysqli'. The 'database' option determines which database is to |
| 111 | + * be used for the connection. The 'select' option determines whether the connector should automatically select |
| 112 | + * the chosen database. |
| 113 | + * |
| 114 | + * Instances are unique to the given options and new objects are only created when a unique options array is |
| 115 | + * passed into the method. This ensures that we don't end up with unnecessary database connection resources. |
| 116 | + * |
| 117 | + * @param array $options Parameters to be passed to the database driver. |
| 118 | + * |
| 119 | + * @return FOFDatabaseDriver A database object. |
| 120 | + * |
| 121 | + * @since 11.1 |
| 122 | + * @deprecated 13.1 (Platform) & 4.0 (CMS) |
| 123 | + */ |
| 124 | + public static function getInstance($options = array()) |
| 125 | + { |
| 126 | + if (class_exists('JLog')) |
| 127 | + { |
| 128 | + JLog::add('FOFDatabase::getInstance() is deprecated, use FOFDatabaseDriver::getInstance() instead.', JLog::WARNING, 'deprecated'); |
| 129 | + } |
| 130 | + |
| 131 | + return FOFDatabaseDriver::getInstance($options); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Splits a string of multiple queries into an array of individual queries. |
| 136 | + * |
| 137 | + * @param string $query Input SQL string with which to split into individual queries. |
| 138 | + * |
| 139 | + * @return array The queries from the input string separated into an array. |
| 140 | + * |
| 141 | + * @since 11.1 |
| 142 | + * @deprecated 13.1 (Platform) & 4.0 (CMS) |
| 143 | + */ |
| 144 | + public static function splitSql($query) |
| 145 | + { |
| 146 | + if (class_exists('JLog')) |
| 147 | + { |
| 148 | + JLog::add('FOFDatabase::splitSql() is deprecated, use FOFDatabaseDriver::splitSql() instead.', JLog::WARNING, 'deprecated'); |
| 149 | + } |
| 150 | + |
| 151 | + return FOFDatabaseDriver::splitSql($query); |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * Return the most recent error message for the database connector. |
| 156 | + * |
| 157 | + * @param boolean $showSQL True to display the SQL statement sent to the database as well as the error. |
| 158 | + * |
| 159 | + * @return string The error message for the most recent query. |
| 160 | + * |
| 161 | + * @since 11.1 |
| 162 | + * @deprecated 13.3 (Platform) & 4.0 (CMS) |
| 163 | + */ |
| 164 | + public function stderr($showSQL = false) |
| 165 | + { |
| 166 | + if (class_exists('JLog')) |
| 167 | + { |
| 168 | + JLog::add('FOFDatabase::stderr() is deprecated.', JLog::WARNING, 'deprecated'); |
| 169 | + } |
| 170 | + |
| 171 | + if ($this->errorNum != 0) |
| 172 | + { |
| 173 | + return JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $this->errorNum, $this->errorMsg) |
| 174 | + . ($showSQL ? "<br />SQL = <pre>$this->sql</pre>" : ''); |
| 175 | + } |
| 176 | + else |
| 177 | + { |
| 178 | + return JText::_('JLIB_DATABASE_FUNCTION_NOERROR'); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + /** |
| 183 | + * Test to see if the connector is available. |
| 184 | + * |
| 185 | + * @return boolean True on success, false otherwise. |
| 186 | + * |
| 187 | + * @since 11.1 |
| 188 | + * @deprecated 12.3 (Platform) & 4.0 (CMS) - Use FOFDatabaseDriver::isSupported() instead. |
| 189 | + */ |
| 190 | + public static function test() |
| 191 | + { |
| 192 | + if (class_exists('JLog')) |
| 193 | + { |
| 194 | + JLog::add('FOFDatabase::test() is deprecated. Use FOFDatabaseDriver::isSupported() instead.', JLog::WARNING, 'deprecated'); |
| 195 | + } |
| 196 | + |
| 197 | + return static::isSupported(); |
| 198 | + } |
| 199 | +} |
0 commit comments