Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / db / DatabaseMysql.php
blobb75d615b107518e830f1c6459c5b2d9a2114da1e
1 <?php
2 /**
3 * This is the MySQL database abstraction layer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Database
24 /**
25 * Database abstraction object for PHP extension mysql.
27 * @ingroup Database
28 * @see Database
30 class DatabaseMysql extends DatabaseMysqlBase {
32 /**
33 * @param $sql string
34 * @return resource
36 protected function doQuery( $sql ) {
37 if ( $this->bufferResults() ) {
38 $ret = mysql_query( $sql, $this->mConn );
39 } else {
40 $ret = mysql_unbuffered_query( $sql, $this->mConn );
42 return $ret;
45 protected function mysqlConnect( $realServer ) {
46 # Load mysql.so if we don't have it
47 wfDl( 'mysql' );
49 # Fail now
50 # Otherwise we get a suppressed fatal error, which is very hard to track down
51 if ( !function_exists( 'mysql_connect' ) ) {
52 throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" );
55 $connFlags = 0;
56 if ( $this->mFlags & DBO_SSL ) {
57 $connFlags |= MYSQL_CLIENT_SSL;
59 if ( $this->mFlags & DBO_COMPRESS ) {
60 $connFlags |= MYSQL_CLIENT_COMPRESS;
63 if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
64 $numAttempts = 2;
65 } else {
66 $numAttempts = 1;
69 $conn = false;
71 for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) {
72 if ( $i > 1 ) {
73 usleep( 1000 );
75 if ( $this->mFlags & DBO_PERSISTENT ) {
76 $conn = mysql_pconnect( $realServer, $this->mUser, $this->mPassword, $connFlags );
77 } else {
78 # Create a new connection...
79 $conn = mysql_connect( $realServer, $this->mUser, $this->mPassword, true, $connFlags );
83 return $conn;
86 /**
87 * @return bool
89 protected function closeConnection() {
90 return mysql_close( $this->mConn );
93 /**
94 * @return int
96 function insertId() {
97 return mysql_insert_id( $this->mConn );
101 * @return int
103 function lastErrno() {
104 if ( $this->mConn ) {
105 return mysql_errno( $this->mConn );
106 } else {
107 return mysql_errno();
112 * @return int
114 function affectedRows() {
115 return mysql_affected_rows( $this->mConn );
119 * @param $db
120 * @return bool
122 function selectDB( $db ) {
123 $this->mDBname = $db;
124 return mysql_select_db( $db, $this->mConn );
128 * @return string
130 function getServerVersion() {
131 return mysql_get_server_info( $this->mConn );
134 protected function mysqlFreeResult( $res ) {
135 return mysql_free_result( $res );
138 protected function mysqlFetchObject( $res ) {
139 return mysql_fetch_object( $res );
142 protected function mysqlFetchArray( $res ) {
143 return mysql_fetch_array( $res );
146 protected function mysqlNumRows( $res ) {
147 return mysql_num_rows( $res );
150 protected function mysqlNumFields( $res ) {
151 return mysql_num_fields( $res );
154 protected function mysqlFetchField( $res, $n ) {
155 return mysql_fetch_field( $res, $n );
158 protected function mysqlFieldName( $res, $n ) {
159 return mysql_field_name( $res, $n );
162 protected function mysqlDataSeek( $res, $row ) {
163 return mysql_data_seek( $res, $row );
166 protected function mysqlError( $conn = null ) {
167 return ( $conn !== null ) ? mysql_error( $conn ) : mysql_error(); // avoid warning
170 protected function mysqlRealEscapeString( $s ) {
171 return mysql_real_escape_string( $s, $this->mConn );
174 protected function mysqlPing() {
175 return mysql_ping( $this->mConn );