Add forgotten RELEASE-NOTES line
[lhc/web/wiklou.git] / includes / db / DatabaseMysql.php
1 <?php
2 /**
3 * This is the MySQL database abstraction layer.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Database
22 */
23
24 /**
25 * Database abstraction object for PHP extension mysql.
26 *
27 * @ingroup Database
28 * @see Database
29 */
30 class DatabaseMysql extends DatabaseMysqlBase {
31
32 /**
33 * @param $sql string
34 * @return resource
35 */
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 );
41 }
42 return $ret;
43 }
44
45 protected function mysqlConnect( $realServer ) {
46 # Fail now
47 # Otherwise we get a suppressed fatal error, which is very hard to track down
48 if ( !extension_loaded( 'mysql' ) ) {
49 throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" );
50 }
51
52 $connFlags = 0;
53 if ( $this->mFlags & DBO_SSL ) {
54 $connFlags |= MYSQL_CLIENT_SSL;
55 }
56 if ( $this->mFlags & DBO_COMPRESS ) {
57 $connFlags |= MYSQL_CLIENT_COMPRESS;
58 }
59
60 if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
61 $numAttempts = 2;
62 } else {
63 $numAttempts = 1;
64 }
65
66 $conn = false;
67
68 for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) {
69 if ( $i > 1 ) {
70 usleep( 1000 );
71 }
72 if ( $this->mFlags & DBO_PERSISTENT ) {
73 $conn = mysql_pconnect( $realServer, $this->mUser, $this->mPassword, $connFlags );
74 } else {
75 # Create a new connection...
76 $conn = mysql_connect( $realServer, $this->mUser, $this->mPassword, true, $connFlags );
77 }
78 }
79
80 return $conn;
81 }
82
83 /**
84 * @return bool
85 */
86 protected function closeConnection() {
87 return mysql_close( $this->mConn );
88 }
89
90 /**
91 * @return int
92 */
93 function insertId() {
94 return mysql_insert_id( $this->mConn );
95 }
96
97 /**
98 * @return int
99 */
100 function lastErrno() {
101 if ( $this->mConn ) {
102 return mysql_errno( $this->mConn );
103 } else {
104 return mysql_errno();
105 }
106 }
107
108 /**
109 * @return int
110 */
111 function affectedRows() {
112 return mysql_affected_rows( $this->mConn );
113 }
114
115 /**
116 * @param $db
117 * @return bool
118 */
119 function selectDB( $db ) {
120 $this->mDBname = $db;
121 return mysql_select_db( $db, $this->mConn );
122 }
123
124 /**
125 * @return string
126 */
127 function getServerVersion() {
128 return mysql_get_server_info( $this->mConn );
129 }
130
131 protected function mysqlFreeResult( $res ) {
132 return mysql_free_result( $res );
133 }
134
135 protected function mysqlFetchObject( $res ) {
136 return mysql_fetch_object( $res );
137 }
138
139 protected function mysqlFetchArray( $res ) {
140 return mysql_fetch_array( $res );
141 }
142
143 protected function mysqlNumRows( $res ) {
144 return mysql_num_rows( $res );
145 }
146
147 protected function mysqlNumFields( $res ) {
148 return mysql_num_fields( $res );
149 }
150
151 protected function mysqlFetchField( $res, $n ) {
152 return mysql_fetch_field( $res, $n );
153 }
154
155 protected function mysqlFieldName( $res, $n ) {
156 return mysql_field_name( $res, $n );
157 }
158
159 protected function mysqlDataSeek( $res, $row ) {
160 return mysql_data_seek( $res, $row );
161 }
162
163 protected function mysqlError( $conn = null ) {
164 return ( $conn !== null ) ? mysql_error( $conn ) : mysql_error(); // avoid warning
165 }
166
167 protected function mysqlRealEscapeString( $s ) {
168 return mysql_real_escape_string( $s, $this->mConn );
169 }
170
171 protected function mysqlPing() {
172 return mysql_ping( $this->mConn );
173 }
174 }