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