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