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
25 * Database abstraction object for PHP extension mysql.
30 class DatabaseMysql
extends DatabaseMysqlBase
{
33 * @return resource False on error
35 protected function doQuery( $sql ) {
36 if ( $this->bufferResults() ) {
37 $ret = mysql_query( $sql, $this->mConn
);
39 $ret = mysql_unbuffered_query( $sql, $this->mConn
);
46 * @param string $realServer
47 * @return bool|resource MySQL Database connection or false on failure to connect
48 * @throws DBConnectionError
50 protected function mysqlConnect( $realServer ) {
52 # Otherwise we get a suppressed fatal error, which is very hard to track down
53 if ( !extension_loaded( 'mysql' ) ) {
54 throw new DBConnectionError(
56 "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n"
61 if ( $this->mFlags
& DBO_SSL
) {
62 $connFlags |
= MYSQL_CLIENT_SSL
;
64 if ( $this->mFlags
& DBO_COMPRESS
) {
65 $connFlags |
= MYSQL_CLIENT_COMPRESS
;
68 if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
76 for ( $i = 0; $i < $numAttempts && !$conn; $i++
) {
80 if ( $this->mFlags
& DBO_PERSISTENT
) {
81 $conn = mysql_pconnect( $realServer, $this->mUser
, $this->mPassword
, $connFlags );
83 # Create a new connection...
84 $conn = mysql_connect( $realServer, $this->mUser
, $this->mPassword
, true, $connFlags );
92 * @param string $charset
95 protected function mysqlSetCharset( $charset ) {
96 if ( function_exists( 'mysql_set_charset' ) ) {
97 return mysql_set_charset( $charset, $this->mConn
);
99 return $this->query( 'SET NAMES ' . $charset, __METHOD__
);
106 protected function closeConnection() {
107 return mysql_close( $this->mConn
);
113 function insertId() {
114 return mysql_insert_id( $this->mConn
);
120 function lastErrno() {
121 if ( $this->mConn
) {
122 return mysql_errno( $this->mConn
);
124 return mysql_errno();
131 function affectedRows() {
132 return mysql_affected_rows( $this->mConn
);
139 function selectDB( $db ) {
140 $this->mDBname
= $db;
142 return mysql_select_db( $db, $this->mConn
);
145 protected function mysqlFreeResult( $res ) {
146 return mysql_free_result( $res );
149 protected function mysqlFetchObject( $res ) {
150 return mysql_fetch_object( $res );
153 protected function mysqlFetchArray( $res ) {
154 return mysql_fetch_array( $res );
157 protected function mysqlNumRows( $res ) {
158 return mysql_num_rows( $res );
161 protected function mysqlNumFields( $res ) {
162 return mysql_num_fields( $res );
165 protected function mysqlFetchField( $res, $n ) {
166 return mysql_fetch_field( $res, $n );
169 protected function mysqlFieldName( $res, $n ) {
170 return mysql_field_name( $res, $n );
173 protected function mysqlFieldType( $res, $n ) {
174 return mysql_field_type( $res, $n );
177 protected function mysqlDataSeek( $res, $row ) {
178 return mysql_data_seek( $res, $row );
181 protected function mysqlError( $conn = null ) {
182 return ( $conn !== null ) ?
mysql_error( $conn ) : mysql_error(); // avoid warning
185 protected function mysqlRealEscapeString( $s ) {
186 return mysql_real_escape_string( $s, $this->mConn
);
189 protected function mysqlPing() {
190 return mysql_ping( $this->mConn
);