wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / db / DatabaseMysql.php
blob5b15147777c68ae7034fc88783f9358874f15deb
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 {
31 /**
32 * @param string $sql
33 * @return resource False on error
35 protected function doQuery( $sql ) {
36 $conn = $this->getBindingHandle();
38 if ( $this->bufferResults() ) {
39 $ret = mysql_query( $sql, $conn );
40 } else {
41 $ret = mysql_unbuffered_query( $sql, $conn );
44 return $ret;
47 /**
48 * @param string $realServer
49 * @return bool|resource MySQL Database connection or false on failure to connect
50 * @throws DBConnectionError
52 protected function mysqlConnect( $realServer ) {
53 # Avoid a suppressed fatal error, which is very hard to track down
54 if ( !extension_loaded( 'mysql' ) ) {
55 throw new DBConnectionError(
56 $this,
57 "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n"
61 $connFlags = 0;
62 if ( $this->mFlags & DBO_SSL ) {
63 $connFlags |= MYSQL_CLIENT_SSL;
65 if ( $this->mFlags & DBO_COMPRESS ) {
66 $connFlags |= MYSQL_CLIENT_COMPRESS;
69 if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
70 $numAttempts = 2;
71 } else {
72 $numAttempts = 1;
75 $conn = false;
77 # The kernel's default SYN retransmission period is far too slow for us,
78 # so we use a short timeout plus a manual retry. Retrying means that a small
79 # but finite rate of SYN packet loss won't cause user-visible errors.
80 for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) {
81 if ( $i > 1 ) {
82 usleep( 1000 );
84 if ( $this->mFlags & DBO_PERSISTENT ) {
85 $conn = mysql_pconnect( $realServer, $this->mUser, $this->mPassword, $connFlags );
86 } else {
87 # Create a new connection...
88 $conn = mysql_connect( $realServer, $this->mUser, $this->mPassword, true, $connFlags );
92 return $conn;
95 /**
96 * @param string $charset
97 * @return bool
99 protected function mysqlSetCharset( $charset ) {
100 $conn = $this->getBindingHandle();
102 if ( function_exists( 'mysql_set_charset' ) ) {
103 return mysql_set_charset( $charset, $conn );
104 } else {
105 return $this->query( 'SET NAMES ' . $charset, __METHOD__ );
110 * @return bool
112 protected function closeConnection() {
113 $conn = $this->getBindingHandle();
115 return mysql_close( $conn );
119 * @return int
121 function insertId() {
122 $conn = $this->getBindingHandle();
124 return mysql_insert_id( $conn );
128 * @return int
130 function lastErrno() {
131 if ( $this->mConn ) {
132 return mysql_errno( $this->mConn );
133 } else {
134 return mysql_errno();
139 * @return int
141 function affectedRows() {
142 $conn = $this->getBindingHandle();
144 return mysql_affected_rows( $conn );
148 * @param string $db
149 * @return bool
151 function selectDB( $db ) {
152 $conn = $this->getBindingHandle();
154 $this->mDBname = $db;
156 return mysql_select_db( $db, $conn );
159 protected function mysqlFreeResult( $res ) {
160 return mysql_free_result( $res );
163 protected function mysqlFetchObject( $res ) {
164 return mysql_fetch_object( $res );
167 protected function mysqlFetchArray( $res ) {
168 return mysql_fetch_array( $res );
171 protected function mysqlNumRows( $res ) {
172 return mysql_num_rows( $res );
175 protected function mysqlNumFields( $res ) {
176 return mysql_num_fields( $res );
179 protected function mysqlFetchField( $res, $n ) {
180 return mysql_fetch_field( $res, $n );
183 protected function mysqlFieldName( $res, $n ) {
184 return mysql_field_name( $res, $n );
187 protected function mysqlFieldType( $res, $n ) {
188 return mysql_field_type( $res, $n );
191 protected function mysqlDataSeek( $res, $row ) {
192 return mysql_data_seek( $res, $row );
195 protected function mysqlError( $conn = null ) {
196 return ( $conn !== null ) ? mysql_error( $conn ) : mysql_error(); // avoid warning
199 protected function mysqlRealEscapeString( $s ) {
200 $conn = $this->getBindingHandle();
202 return mysql_real_escape_string( $s, $conn );
205 protected function mysqlPing() {
206 $conn = $this->getBindingHandle();
208 return mysql_ping( $conn );