Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -0,0 +1,297 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Database abstraction object for mySQL |
| 5 | + * Inherit all methods and properties of Database::Database() |
| 6 | + * |
| 7 | + * @ingroup Database |
| 8 | + * @see Database |
| 9 | + */ |
| 10 | +class DatabaseMysql extends DatabaseBase { |
| 11 | + /*private*/ function doQuery( $sql ) { |
| 12 | + if( $this->bufferResults() ) { |
| 13 | + $ret = mysql_query( $sql, $this->mConn ); |
| 14 | + } else { |
| 15 | + $ret = mysql_unbuffered_query( $sql, $this->mConn ); |
| 16 | + } |
| 17 | + return $ret; |
| 18 | + } |
| 19 | + |
| 20 | + function open( $server, $user, $password, $dbName ) { |
| 21 | + global $wgAllDBsAreLocalhost; |
| 22 | + wfProfileIn( __METHOD__ ); |
| 23 | + |
| 24 | + # Test for missing mysql.so |
| 25 | + # First try to load it |
| 26 | + if (!@extension_loaded('mysql')) { |
| 27 | + @dl('mysql.so'); |
| 28 | + } |
| 29 | + |
| 30 | + # Fail now |
| 31 | + # Otherwise we get a suppressed fatal error, which is very hard to track down |
| 32 | + if ( !function_exists( 'mysql_connect' ) ) { |
| 33 | + throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" ); |
| 34 | + } |
| 35 | + |
| 36 | + # Debugging hack -- fake cluster |
| 37 | + if ( $wgAllDBsAreLocalhost ) { |
| 38 | + $realServer = 'localhost'; |
| 39 | + } else { |
| 40 | + $realServer = $server; |
| 41 | + } |
| 42 | + $this->close(); |
| 43 | + $this->mServer = $server; |
| 44 | + $this->mUser = $user; |
| 45 | + $this->mPassword = $password; |
| 46 | + $this->mDBname = $dbName; |
| 47 | + |
| 48 | + $success = false; |
| 49 | + |
| 50 | + wfProfileIn("dbconnect-$server"); |
| 51 | + |
| 52 | + # The kernel's default SYN retransmission period is far too slow for us, |
| 53 | + # so we use a short timeout plus a manual retry. Retrying means that a small |
| 54 | + # but finite rate of SYN packet loss won't cause user-visible errors. |
| 55 | + $this->mConn = false; |
| 56 | + if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) { |
| 57 | + $numAttempts = 2; |
| 58 | + } else { |
| 59 | + $numAttempts = 1; |
| 60 | + } |
| 61 | + $this->installErrorHandler(); |
| 62 | + for ( $i = 0; $i < $numAttempts && !$this->mConn; $i++ ) { |
| 63 | + if ( $i > 1 ) { |
| 64 | + usleep( 1000 ); |
| 65 | + } |
| 66 | + if ( $this->mFlags & DBO_PERSISTENT ) { |
| 67 | + $this->mConn = mysql_pconnect( $realServer, $user, $password ); |
| 68 | + } else { |
| 69 | + # Create a new connection... |
| 70 | + $this->mConn = mysql_connect( $realServer, $user, $password, true ); |
| 71 | + } |
| 72 | + if ($this->mConn === false) { |
| 73 | + #$iplus = $i + 1; |
| 74 | + #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n"); |
| 75 | + } |
| 76 | + } |
| 77 | + $phpError = $this->restoreErrorHandler(); |
| 78 | + # Always log connection errors |
| 79 | + if ( !$this->mConn ) { |
| 80 | + $error = $this->lastError(); |
| 81 | + if ( !$error ) { |
| 82 | + $error = $phpError; |
| 83 | + } |
| 84 | + wfLogDBError( "Error connecting to {$this->mServer}: $error\n" ); |
| 85 | + wfDebug( "DB connection error\n" ); |
| 86 | + wfDebug( "Server: $server, User: $user, Password: " . |
| 87 | + substr( $password, 0, 3 ) . "..., error: " . mysql_error() . "\n" ); |
| 88 | + $success = false; |
| 89 | + } |
| 90 | + |
| 91 | + wfProfileOut("dbconnect-$server"); |
| 92 | + |
| 93 | + if ( $dbName != '' && $this->mConn !== false ) { |
| 94 | + $success = @/**/mysql_select_db( $dbName, $this->mConn ); |
| 95 | + if ( !$success ) { |
| 96 | + $error = "Error selecting database $dbName on server {$this->mServer} " . |
| 97 | + "from client host " . wfHostname() . "\n"; |
| 98 | + wfLogDBError(" Error selecting database $dbName on server {$this->mServer} \n"); |
| 99 | + wfDebug( $error ); |
| 100 | + } |
| 101 | + } else { |
| 102 | + # Delay USE query |
| 103 | + $success = (bool)$this->mConn; |
| 104 | + } |
| 105 | + |
| 106 | + if ( $success ) { |
| 107 | + $version = $this->getServerVersion(); |
| 108 | + if ( version_compare( $version, '4.1' ) >= 0 ) { |
| 109 | + // Tell the server we're communicating with it in UTF-8. |
| 110 | + // This may engage various charset conversions. |
| 111 | + global $wgDBmysql5; |
| 112 | + if( $wgDBmysql5 ) { |
| 113 | + $this->query( 'SET NAMES utf8', __METHOD__ ); |
| 114 | + } |
| 115 | + // Turn off strict mode |
| 116 | + $this->query( "SET sql_mode = ''", __METHOD__ ); |
| 117 | + } |
| 118 | + |
| 119 | + // Turn off strict mode if it is on |
| 120 | + } else { |
| 121 | + $this->reportConnectionError( $phpError ); |
| 122 | + } |
| 123 | + |
| 124 | + $this->mOpened = $success; |
| 125 | + wfProfileOut( __METHOD__ ); |
| 126 | + return $success; |
| 127 | + } |
| 128 | + |
| 129 | + function close() { |
| 130 | + $this->mOpened = false; |
| 131 | + if ( $this->mConn ) { |
| 132 | + if ( $this->trxLevel() ) { |
| 133 | + $this->immediateCommit(); |
| 134 | + } |
| 135 | + return mysql_close( $this->mConn ); |
| 136 | + } else { |
| 137 | + return true; |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + function freeResult( $res ) { |
| 142 | + if ( $res instanceof ResultWrapper ) { |
| 143 | + $res = $res->result; |
| 144 | + } |
| 145 | + if ( !@/**/mysql_free_result( $res ) ) { |
| 146 | + throw new DBUnexpectedError( $this, "Unable to free MySQL result" ); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + function fetchObject( $res ) { |
| 151 | + if ( $res instanceof ResultWrapper ) { |
| 152 | + $res = $res->result; |
| 153 | + } |
| 154 | + @/**/$row = mysql_fetch_object( $res ); |
| 155 | + if( $this->lastErrno() ) { |
| 156 | + throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); |
| 157 | + } |
| 158 | + return $row; |
| 159 | + } |
| 160 | + |
| 161 | + function fetchRow( $res ) { |
| 162 | + if ( $res instanceof ResultWrapper ) { |
| 163 | + $res = $res->result; |
| 164 | + } |
| 165 | + @/**/$row = mysql_fetch_array( $res ); |
| 166 | + if ( $this->lastErrno() ) { |
| 167 | + throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); |
| 168 | + } |
| 169 | + return $row; |
| 170 | + } |
| 171 | + |
| 172 | + function numRows( $res ) { |
| 173 | + if ( $res instanceof ResultWrapper ) { |
| 174 | + $res = $res->result; |
| 175 | + } |
| 176 | + @/**/$n = mysql_num_rows( $res ); |
| 177 | + if( $this->lastErrno() ) { |
| 178 | + throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( $this->lastError() ) ); |
| 179 | + } |
| 180 | + return $n; |
| 181 | + } |
| 182 | + |
| 183 | + function numFields( $res ) { |
| 184 | + if ( $res instanceof ResultWrapper ) { |
| 185 | + $res = $res->result; |
| 186 | + } |
| 187 | + return mysql_num_fields( $res ); |
| 188 | + } |
| 189 | + |
| 190 | + function fieldName( $res, $n ) { |
| 191 | + if ( $res instanceof ResultWrapper ) { |
| 192 | + $res = $res->result; |
| 193 | + } |
| 194 | + return mysql_field_name( $res, $n ); |
| 195 | + } |
| 196 | + |
| 197 | + function insertId() { return mysql_insert_id( $this->mConn ); } |
| 198 | + |
| 199 | + function dataSeek( $res, $row ) { |
| 200 | + if ( $res instanceof ResultWrapper ) { |
| 201 | + $res = $res->result; |
| 202 | + } |
| 203 | + return mysql_data_seek( $res, $row ); |
| 204 | + } |
| 205 | + |
| 206 | + function lastErrno() { |
| 207 | + if ( $this->mConn ) { |
| 208 | + return mysql_errno( $this->mConn ); |
| 209 | + } else { |
| 210 | + return mysql_errno(); |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + function lastError() { |
| 215 | + if ( $this->mConn ) { |
| 216 | + # Even if it's non-zero, it can still be invalid |
| 217 | + wfSuppressWarnings(); |
| 218 | + $error = mysql_error( $this->mConn ); |
| 219 | + if ( !$error ) { |
| 220 | + $error = mysql_error(); |
| 221 | + } |
| 222 | + wfRestoreWarnings(); |
| 223 | + } else { |
| 224 | + $error = mysql_error(); |
| 225 | + } |
| 226 | + if( $error ) { |
| 227 | + $error .= ' (' . $this->mServer . ')'; |
| 228 | + } |
| 229 | + return $error; |
| 230 | + } |
| 231 | + |
| 232 | + function affectedRows() { return mysql_affected_rows( $this->mConn ); } |
| 233 | + |
| 234 | + function fieldInfo( $table, $field ) { |
| 235 | + $table = $this->tableName( $table ); |
| 236 | + $res = $this->query( "SELECT * FROM $table LIMIT 1" ); |
| 237 | + $n = mysql_num_fields( $res->result ); |
| 238 | + for( $i = 0; $i < $n; $i++ ) { |
| 239 | + $meta = mysql_fetch_field( $res->result, $i ); |
| 240 | + if( $field == $meta->name ) { |
| 241 | + return new MySQLField($meta); |
| 242 | + } |
| 243 | + } |
| 244 | + return false; |
| 245 | + } |
| 246 | + |
| 247 | + function selectDB( $db ) { |
| 248 | + $this->mDBname = $db; |
| 249 | + return mysql_select_db( $db, $this->mConn ); |
| 250 | + } |
| 251 | + |
| 252 | + function strencode( $s ) { |
| 253 | + return mysql_real_escape_string( $s, $this->mConn ); |
| 254 | + } |
| 255 | + |
| 256 | + function ping() { |
| 257 | + if( !function_exists( 'mysql_ping' ) ) { |
| 258 | + wfDebug( "Tried to call mysql_ping but this is ancient PHP version. Faking it!\n" ); |
| 259 | + return true; |
| 260 | + } |
| 261 | + $ping = mysql_ping( $this->mConn ); |
| 262 | + if ( $ping ) { |
| 263 | + return true; |
| 264 | + } |
| 265 | + |
| 266 | + // Need to reconnect manually in MySQL client 5.0.13+ |
| 267 | + if ( version_compare( mysql_get_client_info(), '5.0.13', '>=' ) ) { |
| 268 | + mysql_close( $this->mConn ); |
| 269 | + $this->mOpened = false; |
| 270 | + $this->mConn = false; |
| 271 | + $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname ); |
| 272 | + return true; |
| 273 | + } |
| 274 | + return false; |
| 275 | + } |
| 276 | + |
| 277 | + function getServerVersion() { |
| 278 | + return mysql_get_server_info( $this->mConn ); |
| 279 | + } |
| 280 | +} |
| 281 | + |
| 282 | +/** |
| 283 | + * Legacy support: Database == DatabaseMysql |
| 284 | + */ |
| 285 | +class Database extends DatabaseMysql {} |
| 286 | + |
| 287 | +class MySQLMasterPos { |
| 288 | + var $file, $pos; |
| 289 | + |
| 290 | + function __construct( $file, $pos ) { |
| 291 | + $this->file = $file; |
| 292 | + $this->pos = $pos; |
| 293 | + } |
| 294 | + |
| 295 | + function __toString() { |
| 296 | + return "{$this->file}/{$this->pos}"; |
| 297 | + } |
| 298 | +} |
Property changes on: trunk/phase3/includes/db/DatabaseMysql.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 299 | + native |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -328,115 +328,8 @@ |
329 | 329 | * @param $password String: database user password |
330 | 330 | * @param $dbName String: database name |
331 | 331 | */ |
332 | | - function open( $server, $user, $password, $dbName ) { |
333 | | - global $wgAllDBsAreLocalhost; |
334 | | - wfProfileIn( __METHOD__ ); |
| 332 | + abstract function open( $server, $user, $password, $dbName ); |
335 | 333 | |
336 | | - # Test for missing mysql.so |
337 | | - # First try to load it |
338 | | - if (!@extension_loaded('mysql')) { |
339 | | - @dl('mysql.so'); |
340 | | - } |
341 | | - |
342 | | - # Fail now |
343 | | - # Otherwise we get a suppressed fatal error, which is very hard to track down |
344 | | - if ( !function_exists( 'mysql_connect' ) ) { |
345 | | - throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" ); |
346 | | - } |
347 | | - |
348 | | - # Debugging hack -- fake cluster |
349 | | - if ( $wgAllDBsAreLocalhost ) { |
350 | | - $realServer = 'localhost'; |
351 | | - } else { |
352 | | - $realServer = $server; |
353 | | - } |
354 | | - $this->close(); |
355 | | - $this->mServer = $server; |
356 | | - $this->mUser = $user; |
357 | | - $this->mPassword = $password; |
358 | | - $this->mDBname = $dbName; |
359 | | - |
360 | | - $success = false; |
361 | | - |
362 | | - wfProfileIn("dbconnect-$server"); |
363 | | - |
364 | | - # The kernel's default SYN retransmission period is far too slow for us, |
365 | | - # so we use a short timeout plus a manual retry. Retrying means that a small |
366 | | - # but finite rate of SYN packet loss won't cause user-visible errors. |
367 | | - $this->mConn = false; |
368 | | - if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) { |
369 | | - $numAttempts = 2; |
370 | | - } else { |
371 | | - $numAttempts = 1; |
372 | | - } |
373 | | - $this->installErrorHandler(); |
374 | | - for ( $i = 0; $i < $numAttempts && !$this->mConn; $i++ ) { |
375 | | - if ( $i > 1 ) { |
376 | | - usleep( 1000 ); |
377 | | - } |
378 | | - if ( $this->mFlags & DBO_PERSISTENT ) { |
379 | | - $this->mConn = mysql_pconnect( $realServer, $user, $password ); |
380 | | - } else { |
381 | | - # Create a new connection... |
382 | | - $this->mConn = mysql_connect( $realServer, $user, $password, true ); |
383 | | - } |
384 | | - if ($this->mConn === false) { |
385 | | - #$iplus = $i + 1; |
386 | | - #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n"); |
387 | | - } |
388 | | - } |
389 | | - $phpError = $this->restoreErrorHandler(); |
390 | | - # Always log connection errors |
391 | | - if ( !$this->mConn ) { |
392 | | - $error = $this->lastError(); |
393 | | - if ( !$error ) { |
394 | | - $error = $phpError; |
395 | | - } |
396 | | - wfLogDBError( "Error connecting to {$this->mServer}: $error\n" ); |
397 | | - wfDebug( "DB connection error\n" ); |
398 | | - wfDebug( "Server: $server, User: $user, Password: " . |
399 | | - substr( $password, 0, 3 ) . "..., error: " . mysql_error() . "\n" ); |
400 | | - $success = false; |
401 | | - } |
402 | | - |
403 | | - wfProfileOut("dbconnect-$server"); |
404 | | - |
405 | | - if ( $dbName != '' && $this->mConn !== false ) { |
406 | | - $success = @/**/mysql_select_db( $dbName, $this->mConn ); |
407 | | - if ( !$success ) { |
408 | | - $error = "Error selecting database $dbName on server {$this->mServer} " . |
409 | | - "from client host " . wfHostname() . "\n"; |
410 | | - wfLogDBError(" Error selecting database $dbName on server {$this->mServer} \n"); |
411 | | - wfDebug( $error ); |
412 | | - } |
413 | | - } else { |
414 | | - # Delay USE query |
415 | | - $success = (bool)$this->mConn; |
416 | | - } |
417 | | - |
418 | | - if ( $success ) { |
419 | | - $version = $this->getServerVersion(); |
420 | | - if ( version_compare( $version, '4.1' ) >= 0 ) { |
421 | | - // Tell the server we're communicating with it in UTF-8. |
422 | | - // This may engage various charset conversions. |
423 | | - global $wgDBmysql5; |
424 | | - if( $wgDBmysql5 ) { |
425 | | - $this->query( 'SET NAMES utf8', __METHOD__ ); |
426 | | - } |
427 | | - // Turn off strict mode |
428 | | - $this->query( "SET sql_mode = ''", __METHOD__ ); |
429 | | - } |
430 | | - |
431 | | - // Turn off strict mode if it is on |
432 | | - } else { |
433 | | - $this->reportConnectionError( $phpError ); |
434 | | - } |
435 | | - |
436 | | - $this->mOpened = $success; |
437 | | - wfProfileOut( __METHOD__ ); |
438 | | - return $success; |
439 | | - } |
440 | | - |
441 | 334 | protected function installErrorHandler() { |
442 | 335 | $this->mPHPError = false; |
443 | 336 | $this->htmlErrors = ini_set( 'html_errors', '0' ); |
— | — | @@ -467,18 +360,7 @@ |
468 | 361 | * |
469 | 362 | * @return Bool operation success. true if already closed. |
470 | 363 | */ |
471 | | - function close() |
472 | | - { |
473 | | - $this->mOpened = false; |
474 | | - if ( $this->mConn ) { |
475 | | - if ( $this->trxLevel() ) { |
476 | | - $this->immediateCommit(); |
477 | | - } |
478 | | - return mysql_close( $this->mConn ); |
479 | | - } else { |
480 | | - return true; |
481 | | - } |
482 | | - } |
| 364 | + abstract function close(); |
483 | 365 | |
484 | 366 | /** |
485 | 367 | * @param $error String: fallback error message, used if none is given by MySQL |
— | — | @@ -630,14 +512,7 @@ |
631 | 513 | * @return Result object to feed to fetchObject, fetchRow, ...; or false on failure |
632 | 514 | * @private |
633 | 515 | */ |
634 | | - /*private*/ function doQuery( $sql ) { |
635 | | - if( $this->bufferResults() ) { |
636 | | - $ret = mysql_query( $sql, $this->mConn ); |
637 | | - } else { |
638 | | - $ret = mysql_unbuffered_query( $sql, $this->mConn ); |
639 | | - } |
640 | | - return $ret; |
641 | | - } |
| 516 | + /*private*/ abstract function doQuery( $sql ); |
642 | 517 | |
643 | 518 | /** |
644 | 519 | * @param $error String |
— | — | @@ -762,14 +637,7 @@ |
763 | 638 | * Free a result object |
764 | 639 | * @param $res Mixed: A SQL result |
765 | 640 | */ |
766 | | - function freeResult( $res ) { |
767 | | - if ( $res instanceof ResultWrapper ) { |
768 | | - $res = $res->result; |
769 | | - } |
770 | | - if ( !@/**/mysql_free_result( $res ) ) { |
771 | | - throw new DBUnexpectedError( $this, "Unable to free MySQL result" ); |
772 | | - } |
773 | | - } |
| 641 | + abstract function freeResult( $res ); |
774 | 642 | |
775 | 643 | /** |
776 | 644 | * Fetch the next row from the given result object, in object form. |
— | — | @@ -780,16 +648,7 @@ |
781 | 649 | * @return MySQL row object |
782 | 650 | * @throws DBUnexpectedError Thrown if the database returns an error |
783 | 651 | */ |
784 | | - function fetchObject( $res ) { |
785 | | - if ( $res instanceof ResultWrapper ) { |
786 | | - $res = $res->result; |
787 | | - } |
788 | | - @/**/$row = mysql_fetch_object( $res ); |
789 | | - if( $this->lastErrno() ) { |
790 | | - throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); |
791 | | - } |
792 | | - return $row; |
793 | | - } |
| 652 | + abstract function fetchObject( $res ); |
794 | 653 | |
795 | 654 | /** |
796 | 655 | * Fetch the next row from the given result object, in associative array |
— | — | @@ -799,43 +658,20 @@ |
800 | 659 | * @return MySQL row object |
801 | 660 | * @throws DBUnexpectedError Thrown if the database returns an error |
802 | 661 | */ |
803 | | - function fetchRow( $res ) { |
804 | | - if ( $res instanceof ResultWrapper ) { |
805 | | - $res = $res->result; |
806 | | - } |
807 | | - @/**/$row = mysql_fetch_array( $res ); |
808 | | - if ( $this->lastErrno() ) { |
809 | | - throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); |
810 | | - } |
811 | | - return $row; |
812 | | - } |
| 662 | + abstract function fetchRow( $res ); |
813 | 663 | |
814 | 664 | /** |
815 | 665 | * Get the number of rows in a result object |
816 | 666 | * @param $res Mixed: A SQL result |
817 | 667 | */ |
818 | | - function numRows( $res ) { |
819 | | - if ( $res instanceof ResultWrapper ) { |
820 | | - $res = $res->result; |
821 | | - } |
822 | | - @/**/$n = mysql_num_rows( $res ); |
823 | | - if( $this->lastErrno() ) { |
824 | | - throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( $this->lastError() ) ); |
825 | | - } |
826 | | - return $n; |
827 | | - } |
| 668 | + abstract function numRows( $res ); |
828 | 669 | |
829 | 670 | /** |
830 | 671 | * Get the number of fields in a result object |
831 | 672 | * See documentation for mysql_num_fields() |
832 | 673 | * @param $res Mixed: A SQL result |
833 | 674 | */ |
834 | | - function numFields( $res ) { |
835 | | - if ( $res instanceof ResultWrapper ) { |
836 | | - $res = $res->result; |
837 | | - } |
838 | | - return mysql_num_fields( $res ); |
839 | | - } |
| 675 | + abstract function numFields( $res ); |
840 | 676 | |
841 | 677 | /** |
842 | 678 | * Get a field name in a result object |
— | — | @@ -844,12 +680,7 @@ |
845 | 681 | * @param $res Mixed: A SQL result |
846 | 682 | * @param $n Integer |
847 | 683 | */ |
848 | | - function fieldName( $res, $n ) { |
849 | | - if ( $res instanceof ResultWrapper ) { |
850 | | - $res = $res->result; |
851 | | - } |
852 | | - return mysql_field_name( $res, $n ); |
853 | | - } |
| 684 | + abstract function fieldName( $res, $n ); |
854 | 685 | |
855 | 686 | /** |
856 | 687 | * Get the inserted value of an auto-increment row |
— | — | @@ -861,7 +692,7 @@ |
862 | 693 | * $dbw->insert('page',array('page_id' => $id)); |
863 | 694 | * $id = $dbw->insertId(); |
864 | 695 | */ |
865 | | - function insertId() { return mysql_insert_id( $this->mConn ); } |
| 696 | + abstract function insertId(); |
866 | 697 | |
867 | 698 | /** |
868 | 699 | * Change the position of the cursor in a result object |
— | — | @@ -869,51 +700,25 @@ |
870 | 701 | * @param $res Mixed: A SQL result |
871 | 702 | * @param $row Mixed: Either MySQL row or ResultWrapper |
872 | 703 | */ |
873 | | - function dataSeek( $res, $row ) { |
874 | | - if ( $res instanceof ResultWrapper ) { |
875 | | - $res = $res->result; |
876 | | - } |
877 | | - return mysql_data_seek( $res, $row ); |
878 | | - } |
| 704 | + abstract function dataSeek( $res, $row ); |
879 | 705 | |
880 | 706 | /** |
881 | 707 | * Get the last error number |
882 | 708 | * See mysql_errno() |
883 | 709 | */ |
884 | | - function lastErrno() { |
885 | | - if ( $this->mConn ) { |
886 | | - return mysql_errno( $this->mConn ); |
887 | | - } else { |
888 | | - return mysql_errno(); |
889 | | - } |
890 | | - } |
| 710 | + abstract function lastErrno(); |
891 | 711 | |
892 | 712 | /** |
893 | 713 | * Get a description of the last error |
894 | 714 | * See mysql_error() for more details |
895 | 715 | */ |
896 | | - function lastError() { |
897 | | - if ( $this->mConn ) { |
898 | | - # Even if it's non-zero, it can still be invalid |
899 | | - wfSuppressWarnings(); |
900 | | - $error = mysql_error( $this->mConn ); |
901 | | - if ( !$error ) { |
902 | | - $error = mysql_error(); |
903 | | - } |
904 | | - wfRestoreWarnings(); |
905 | | - } else { |
906 | | - $error = mysql_error(); |
907 | | - } |
908 | | - if( $error ) { |
909 | | - $error .= ' (' . $this->mServer . ')'; |
910 | | - } |
911 | | - return $error; |
912 | | - } |
| 716 | + abstract function lastError(); |
| 717 | + |
913 | 718 | /** |
914 | 719 | * Get the number of rows affected by the last write query |
915 | 720 | * See mysql_affected_rows() for more details |
916 | 721 | */ |
917 | | - function affectedRows() { return mysql_affected_rows( $this->mConn ); } |
| 722 | + abstract function affectedRows(); |
918 | 723 | |
919 | 724 | /** |
920 | 725 | * Simple UPDATE wrapper |
— | — | @@ -1258,18 +1063,7 @@ |
1259 | 1064 | * @param $table |
1260 | 1065 | * @param $field |
1261 | 1066 | */ |
1262 | | - function fieldInfo( $table, $field ) { |
1263 | | - $table = $this->tableName( $table ); |
1264 | | - $res = $this->query( "SELECT * FROM $table LIMIT 1" ); |
1265 | | - $n = mysql_num_fields( $res->result ); |
1266 | | - for( $i = 0; $i < $n; $i++ ) { |
1267 | | - $meta = mysql_fetch_field( $res->result, $i ); |
1268 | | - if( $field == $meta->name ) { |
1269 | | - return new MySQLField($meta); |
1270 | | - } |
1271 | | - } |
1272 | | - return false; |
1273 | | - } |
| 1067 | + abstract function fieldInfo( $table, $field ); |
1274 | 1068 | |
1275 | 1069 | /** |
1276 | 1070 | * mysql_field_type() wrapper |
— | — | @@ -1459,10 +1253,7 @@ |
1460 | 1254 | /** |
1461 | 1255 | * Change the current database |
1462 | 1256 | */ |
1463 | | - function selectDB( $db ) { |
1464 | | - $this->mDBname = $db; |
1465 | | - return mysql_select_db( $db, $this->mConn ); |
1466 | | - } |
| 1257 | + abstract function selectDB( $db ); |
1467 | 1258 | |
1468 | 1259 | /** |
1469 | 1260 | * Get the current DB name |
— | — | @@ -1638,9 +1429,7 @@ |
1639 | 1430 | * @param $s String: to be slashed. |
1640 | 1431 | * @return String: slashed string. |
1641 | 1432 | */ |
1642 | | - function strencode( $s ) { |
1643 | | - return mysql_real_escape_string( $s, $this->mConn ); |
1644 | | - } |
| 1433 | + abstract function strencode( $s ); |
1645 | 1434 | |
1646 | 1435 | /** |
1647 | 1436 | * If it's a string, adds quotes and backslashes |
— | — | @@ -2128,34 +1917,13 @@ |
2129 | 1918 | /** |
2130 | 1919 | * @return String: Version information from the database |
2131 | 1920 | */ |
2132 | | - function getServerVersion() { |
2133 | | - return mysql_get_server_info( $this->mConn ); |
2134 | | - } |
| 1921 | + abstract function getServerVersion(); |
2135 | 1922 | |
2136 | 1923 | /** |
2137 | 1924 | * Ping the server and try to reconnect if it there is no connection |
2138 | 1925 | */ |
2139 | | - function ping() { |
2140 | | - if( !function_exists( 'mysql_ping' ) ) { |
2141 | | - wfDebug( "Tried to call mysql_ping but this is ancient PHP version. Faking it!\n" ); |
2142 | | - return true; |
2143 | | - } |
2144 | | - $ping = mysql_ping( $this->mConn ); |
2145 | | - if ( $ping ) { |
2146 | | - return true; |
2147 | | - } |
| 1926 | + abstract function ping(); |
2148 | 1927 | |
2149 | | - // Need to reconnect manually in MySQL client 5.0.13+ |
2150 | | - if ( version_compare( mysql_get_client_info(), '5.0.13', '>=' ) ) { |
2151 | | - mysql_close( $this->mConn ); |
2152 | | - $this->mOpened = false; |
2153 | | - $this->mConn = false; |
2154 | | - $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname ); |
2155 | | - return true; |
2156 | | - } |
2157 | | - return false; |
2158 | | - } |
2159 | | - |
2160 | 1928 | /** |
2161 | 1929 | * Get slave lag. |
2162 | 1930 | * At the moment, this will only work if the DB user has the PROCESS privilege |
— | — | @@ -2435,22 +2203,7 @@ |
2436 | 2204 | } |
2437 | 2205 | } |
2438 | 2206 | |
2439 | | -/** |
2440 | | - * Database abstraction object for mySQL |
2441 | | - * Inherit all methods and properties of Database::Database() |
2442 | | - * |
2443 | | - * @ingroup Database |
2444 | | - * @see Database |
2445 | | - */ |
2446 | | -class DatabaseMysql extends DatabaseBase { |
2447 | | - # Inherit all |
2448 | | -} |
2449 | 2207 | |
2450 | | -/** |
2451 | | - * Legacy support: Database == DatabaseMysql |
2452 | | - */ |
2453 | | -class Database extends DatabaseMysql {} |
2454 | | - |
2455 | 2208 | /****************************************************************************** |
2456 | 2209 | * Utility classes |
2457 | 2210 | *****************************************************************************/ |
— | — | @@ -2902,16 +2655,3 @@ |
2903 | 2656 | return $this->current() !== false; |
2904 | 2657 | } |
2905 | 2658 | } |
2906 | | - |
2907 | | -class MySQLMasterPos { |
2908 | | - var $file, $pos; |
2909 | | - |
2910 | | - function __construct( $file, $pos ) { |
2911 | | - $this->file = $file; |
2912 | | - $this->pos = $pos; |
2913 | | - } |
2914 | | - |
2915 | | - function __toString() { |
2916 | | - return "{$this->file}/{$this->pos}"; |
2917 | | - } |
2918 | | -} |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -302,10 +302,10 @@ |
303 | 303 | # includes/db |
304 | 304 | 'Blob' => 'includes/db/Database.php', |
305 | 305 | 'ChronologyProtector' => 'includes/db/LBFactory.php', |
306 | | - 'Database' => 'includes/db/Database.php', |
| 306 | + 'Database' => 'includes/db/DatabaseMysql.php', |
307 | 307 | 'DatabaseBase' => 'includes/db/Database.php', |
308 | 308 | 'DatabaseMssql' => 'includes/db/DatabaseMssql.php', |
309 | | - 'DatabaseMysql' => 'includes/db/Database.php', |
| 309 | + 'DatabaseMysql' => 'includes/db/DatabaseMysql.php', |
310 | 310 | 'DatabaseOracle' => 'includes/db/DatabaseOracle.php', |
311 | 311 | 'DatabasePostgres' => 'includes/db/DatabasePostgres.php', |
312 | 312 | 'DatabaseSqlite' => 'includes/db/DatabaseSqlite.php', |
— | — | @@ -322,7 +322,7 @@ |
323 | 323 | 'LoadMonitor_MySQL' => 'includes/db/LoadMonitor.php', |
324 | 324 | 'MSSQLField' => 'includes/db/DatabaseMssql.php', |
325 | 325 | 'MySQLField' => 'includes/db/Database.php', |
326 | | - 'MySQLMasterPos' => 'includes/db/Database.php', |
| 326 | + 'MySQLMasterPos' => 'includes/db/DatabaseMysql.php', |
327 | 327 | 'ORABlob' => 'includes/db/DatabaseOracle.php', |
328 | 328 | 'ORAResult' => 'includes/db/DatabaseOracle.php', |
329 | 329 | 'PostgresField' => 'includes/db/DatabasePostgres.php', |