00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 include_once( "lib/ezutils/classes/ezdebug.php" );
00043 include_once( "lib/ezutils/classes/ezini.php" );
00044 include_once( "lib/ezdb/classes/ezdbinterface.php" );
00045
00046 class eZMySQLDB extends eZDBInterface
00047 {
00048
00049
00050
00051 function eZMySQLDB( $parameters )
00052 {
00053 $this->eZDBInterface( $parameters );
00054
00055 $this->CharsetMapping = array( 'iso-8859-1' => 'latin1',
00056 'iso-8859-2' => 'latin2',
00057 'iso-8859-8' => 'hebrew',
00058 'iso-8859-7' => 'greek',
00059 'iso-8859-9' => 'latin5',
00060 'iso-8859-13' => 'latin7',
00061 'windows-1250' => 'cp1250',
00062 'windows-1251' => 'cp1251',
00063 'windows-1256' => 'cp1256',
00064 'windows-1257' => 'cp1257',
00065 'utf-8' => 'utf8',
00066 'koi8-r' => 'koi8r',
00067 'koi8-u' => 'koi8u' );
00068
00069 if ( !extension_loaded( 'mysql' ) )
00070 {
00071 if ( function_exists( 'eZAppendWarningItem' ) )
00072 {
00073 eZAppendWarningItem( array( 'error' => array( 'type' => 'ezdb',
00074 'number' => EZ_DB_ERROR_MISSING_EXTENSION ),
00075 'text' => 'MySQL extension was not found, the DB handler will not be initialized.' ) );
00076 $this->IsConnected = false;
00077 }
00078 eZDebug::writeWarning( 'MySQL extension was not found, the DB handler will not be initialized.', 'eZMySQLDB' );
00079 return;
00080 }
00081
00082
00083 if ( $this->DBWriteConnection == false )
00084 {
00085 $connection = $this->connect( $this->Server, $this->DB, $this->User, $this->Password, $this->SocketPath, $this->Charset );
00086 if ( $this->IsConnected )
00087 {
00088 $this->DBWriteConnection = $connection;
00089 }
00090 }
00091
00092
00093 if ( $this->DBConnection == false )
00094 {
00095 if ( $this->UseSlaveServer === true )
00096 {
00097 $connection = $this->connect( $this->SlaveServer, $this->SlaveDB, $this->SlaveUser, $this->SlavePassword, $this->SocketPath, $this->Charset );
00098 }
00099 else
00100 {
00101 $connection =& $this->DBWriteConnection;
00102 }
00103
00104 if ( $connection and $this->DBWriteConnection )
00105 {
00106 $this->DBConnection = $connection;
00107 $this->IsConnected = true;
00108 }
00109 }
00110
00111
00112 $this->TempTableList = array();
00113
00114 eZDebug::createAccumulatorGroup( 'mysql_total', 'Mysql Total' );
00115 }
00116
00117
00118
00119
00120
00121 function connect( $server, $db, $user, $password, $socketPath, $charset = null )
00122 {
00123 $connection = false;
00124
00125 if ( $socketPath !== false )
00126 {
00127 ini_set( "mysql.default_socket", $socketPath );
00128 }
00129
00130 if ( $this->UsePersistentConnection == true )
00131 {
00132 $connection = mysql_pconnect( $server, $user, $password );
00133 }
00134 else
00135 {
00136 $connection = mysql_connect( $server, $user, $password, true );
00137 }
00138 $dbErrorText = mysql_error();
00139 $maxAttempts = $this->connectRetryCount();
00140 $waitTime = $this->connectRetryWaitTime();
00141 $numAttempts = 1;
00142 while ( $connection == false and $numAttempts <= $maxAttempts )
00143 {
00144 sleep( $waitTime );
00145 if ( $this->UsePersistentConnection == true )
00146 {
00147 $connection = mysql_pconnect( $this->Server, $this->User, $this->Password );
00148 }
00149 else
00150 {
00151 $connection = mysql_connect( $this->Server, $this->User, $this->Password );
00152 }
00153 $numAttempts++;
00154 }
00155 $this->setError();
00156
00157 $this->IsConnected = true;
00158
00159 if ( $connection == false )
00160 {
00161 eZDebug::writeError( "Connection error: Couldn't connect to database. Please try again later or inform the system administrator.\n$dbErrorText", "eZMySQLDB" );
00162 $this->IsConnected = false;
00163 }
00164
00165 if ( $this->IsConnected && $db != null )
00166 {
00167 $ret = mysql_select_db( $db, $connection );
00168 $this->setError();
00169 if ( !$ret )
00170 {
00171 eZDebug::writeError( "Connection error: " . mysql_errno( $connection ) . ": " . mysql_error( $connection ), "eZMySQLDB" );
00172 $this->IsConnected = false;
00173 }
00174 }
00175
00176 if ( $charset !== null )
00177 {
00178 $originalCharset = $charset;
00179 include_once( 'lib/ezi18n/classes/ezcharsetinfo.php' );
00180 $charset = eZCharsetInfo::realCharsetCode( $charset );
00181
00182 if ( isset( $this->CharsetMapping[ $charset ] ) )
00183 $charset = $this->CharsetMapping[ $charset ];
00184 }
00185
00186 if ( $this->IsConnected and $charset !== null and $this->isCharsetSupported( $charset ) )
00187 {
00188 $versionInfo = $this->databaseServerVersion();
00189
00190
00191
00192
00193 if ( version_compare( $versionInfo['string'], '4.1.1' ) >= 0 )
00194 {
00195 $query = "SET NAMES '" . $charset . "'";
00196 $status = mysql_query( $query, $connection );
00197 $this->reportQuery( 'eZMySQLDB', $query, false, false );
00198 if ( !$status )
00199 {
00200 $this->setError();
00201 eZDebug::writeWarning( "Connection warning: " . mysql_errno( $connection ) . ": " . mysql_error( $connection ), "eZMySQLDB" );
00202 }
00203 }
00204 }
00205
00206 return $connection;
00207 }
00208
00209
00210
00211
00212 function databaseName()
00213 {
00214 return 'mysql';
00215 }
00216
00217
00218
00219
00220 function bindingType( )
00221 {
00222 return EZ_DB_BINDING_NO;
00223 }
00224
00225
00226
00227
00228 function bindVariable( &$value, $fieldDef = false )
00229 {
00230 return $value;
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 function checkCharset( $charset, &$currentCharset )
00245 {
00246
00247 if ( !$this->DB )
00248 return true;
00249
00250 $versionInfo = $this->databaseServerVersion();
00251
00252
00253
00254
00255
00256 if ( version_compare( $versionInfo['string'], '4.1.1' ) < 0 )
00257 return true;
00258
00259 include_once( 'lib/ezi18n/classes/ezcharsetinfo.php' );
00260
00261 if ( is_array( $charset ) )
00262 {
00263 foreach ( $charset as $charsetItem )
00264 $realCharset[] = eZCharsetInfo::realCharsetCode( $charsetItem );
00265 }
00266 else
00267 $realCharset = eZCharsetInfo::realCharsetCode( $charset );
00268
00269 return $this->checkCharsetPriv( $realCharset, $currentCharset );
00270 }
00271
00272
00273
00274
00275 function checkCharsetPriv( $charset, &$currentCharset )
00276 {
00277 $query = "SHOW CREATE DATABASE `{$this->DB}`";
00278 $status = mysql_query( $query, $this->DBConnection );
00279 $this->reportQuery( 'eZMySQLDB', $query, false, false );
00280 if ( !$status )
00281 {
00282 $this->setError();
00283 eZDebug::writeWarning( "Connection warning: " . mysql_errno( $this->DBConnection ) . ": " . mysql_error( $this->DBConnection ), "eZMySQLDB" );
00284 return false;
00285 }
00286
00287 $numRows = mysql_num_rows( $status );
00288 if ( $numRows == 0 )
00289 return false;
00290
00291 for ( $i = 0; $i < $numRows; ++$i )
00292 {
00293 $tmpRow = mysql_fetch_array( $status, MYSQL_ASSOC );
00294 if ( $tmpRow['Database'] == $this->DB )
00295 {
00296 $createText = $tmpRow['Create Database'];
00297 if ( preg_match( '#DEFAULT CHARACTER SET ([a-zA-Z0-9_-]+)#', $createText, $matches ) )
00298 {
00299 $currentCharset = $matches[1];
00300 include_once( 'lib/ezi18n/classes/ezcharsetinfo.php' );
00301 $currentCharset = eZCharsetInfo::realCharsetCode( $currentCharset );
00302
00303
00304 $key = array_search( $currentCharset, $this->CharsetMapping );
00305 $unmappedCurrentCharset = ( $key === false ) ? $currentCharset : $key;
00306
00307 if ( is_array( $charset ) )
00308 {
00309 if ( in_array( $unmappedCurrentCharset, $charset ) )
00310 {
00311 return $unmappedCurrentCharset;
00312 }
00313 }
00314 else if ( $unmappedCurrentCharset == $charset )
00315 {
00316 return true;
00317 }
00318 return false;
00319 }
00320 break;
00321 }
00322 }
00323 return true;
00324 }
00325
00326
00327
00328
00329 function query( $sql, $server = false )
00330 {
00331 if ( $this->IsConnected )
00332 {
00333 eZDebug::accumulatorStart( 'mysql_query', 'mysql_total', 'Mysql_queries' );
00334 $orig_sql = $sql;
00335
00336 if ( $this->InputTextCodec )
00337 {
00338 eZDebug::accumulatorStart( 'mysql_conversion', 'mysql_total', 'String conversion in mysql' );
00339 $sql = $this->InputTextCodec->convertString( $sql );
00340 eZDebug::accumulatorStop( 'mysql_conversion' );
00341 }
00342
00343 if ( $this->OutputSQL )
00344 {
00345 $this->startTimer();
00346 }
00347
00348 $sql = trim( $sql );
00349
00350
00351 if ( $server === false )
00352 {
00353 $server = strncasecmp( $sql, 'select', 6 ) === 0 && $this->TransactionCounter == 0 ?
00354 EZ_DB_SERVER_SLAVE : EZ_DB_SERVER_MASTER;
00355 }
00356
00357 $connection = ( $server == EZ_DB_SERVER_SLAVE ) ? $this->DBConnection : $this->DBWriteConnection;
00358
00359 $analysisText = false;
00360
00361
00362
00363 if ( $this->QueryAnalysisOutput )
00364 {
00365 $analysisResult = mysql_query( 'EXPLAIN ' . $sql, $connection );
00366 if ( $analysisResult )
00367 {
00368 $numRows = mysql_num_rows( $analysisResult );
00369 $rows = array();
00370 if ( $numRows > 0 )
00371 {
00372 for ( $i = 0; $i < $numRows; ++$i )
00373 {
00374 if ( $this->InputTextCodec )
00375 {
00376 $tmpRow = mysql_fetch_array( $analysisResult, MYSQL_ASSOC );
00377 $convRow = array();
00378 foreach( $tmpRow as $key => $row )
00379 {
00380 $convRow[$key] = $this->OutputTextCodec->convertString( $row );
00381 }
00382 $rows[$i] = $convRow;
00383 }
00384 else
00385 $rows[$i] = mysql_fetch_array( $analysisResult, MYSQL_ASSOC );
00386 }
00387 }
00388
00389
00390 $columns = array();
00391 foreach ( $rows as $row )
00392 {
00393 foreach ( $row as $col => $data )
00394 {
00395 if ( !isset( $columns[$col] ) )
00396 $columns[$col] = array( 'name' => $col,
00397 'size' => strlen( $col ) );
00398 $columns[$col]['size'] = max( $columns[$col]['size'], strlen( $data ) );
00399 }
00400 }
00401
00402 $analysisText = '';
00403 $delimiterLine = array();
00404
00405
00406
00407
00408
00409
00410
00411
00412 foreach ( $columns as $col )
00413 {
00414 $delimiterLine[] = str_repeat( '-', $col['size'] + 2 );
00415 $colLine[] = ' ' . str_pad( $col['name'], $col['size'], ' ', STR_PAD_RIGHT ) . ' ';
00416 }
00417 $delimiterLine = '+' . join( '+', $delimiterLine ) . "+\n";
00418 $analysisText = $delimiterLine;
00419 $analysisText .= '|' . join( '|', $colLine ) . "|\n";
00420 $analysisText .= $delimiterLine;
00421
00422
00423 foreach ( $rows as $row )
00424 {
00425 $rowLine = array();
00426 foreach ( $columns as $col )
00427 {
00428 $name = $col['name'];
00429 $size = $col['size'];
00430 $data = isset( $row[$name] ) ? $row[$name] : '';
00431
00432 $rowLine[] = ' ' . str_pad( $row[$name], $size, ' ',
00433 is_numeric( $row[$name] ) ? STR_PAD_LEFT : STR_PAD_RIGHT ) . ' ';
00434 }
00435 $analysisText .= '|' . join( '|', $rowLine ) . "|\n";
00436 $analysisText .= $delimiterLine;
00437 }
00438
00439
00440 unset( $rows, $delimiterLine, $colLine, $columns );
00441 }
00442 }
00443
00444 $result = mysql_query( $sql, $connection );
00445
00446 if ( $this->RecordError and !$result )
00447 $this->setError();
00448
00449 if ( $this->OutputSQL )
00450 {
00451 $this->endTimer();
00452
00453 if ($this->timeTaken() > $this->SlowSQLTimeout)
00454 {
00455 $num_rows = mysql_affected_rows( $connection );
00456 $text = $sql;
00457
00458
00459 if ( $analysisText !== false )
00460 $text = "EXPLAIN\n" . $text . "\n\nANALYSIS:\n" . $analysisText;
00461
00462 $this->reportQuery( ( $server == EZ_DB_SERVER_MASTER ? 'on master : ' : '' ) . 'eZMySQLDB', $text, $num_rows, $this->timeTaken() );
00463 }
00464 }
00465 eZDebug::accumulatorStop( 'mysql_query' );
00466 if ( $result )
00467 {
00468 return $result;
00469 }
00470 else
00471 {
00472 eZDebug::writeError( "Query error: " . mysql_error( $connection ) . ". Query: ". $sql, "eZMySQLDB" );
00473 $oldRecordError = $this->RecordError;
00474
00475 $this->RecordError = false;
00476 mysql_query( 'UNLOCK TABLES', $connection );
00477 $this->RecordError = $oldRecordError;
00478
00479 $this->reportError();
00480
00481 return false;
00482 }
00483 }
00484 else
00485 {
00486 eZDebug::writeError( "Trying to do a query without being connected to a database!", "eZMySQLDB" );
00487 }
00488
00489
00490 }
00491
00492
00493
00494
00495 function arrayQuery( $sql, $params = array(), $server = false )
00496 {
00497 $retArray = array();
00498 if ( $this->IsConnected )
00499 {
00500 $limit = false;
00501 $offset = 0;
00502 $column = false;
00503
00504 if ( is_array( $params ) )
00505 {
00506 if ( isset( $params["limit"] ) and is_numeric( $params["limit"] ) )
00507 $limit = $params["limit"];
00508
00509 if ( isset( $params["offset"] ) and is_numeric( $params["offset"] ) )
00510 $offset = $params["offset"];
00511
00512 if ( isset( $params["column"] ) and ( is_numeric( $params["column"] ) or is_string( $params["column"] ) ) )
00513 $column = $params["column"];
00514 }
00515
00516 if ( $limit !== false and is_numeric( $limit ) )
00517 {
00518 $sql .= "\nLIMIT $offset, $limit ";
00519 }
00520 else if ( $offset !== false and is_numeric( $offset ) and $offset > 0 )
00521 {
00522 $sql .= "\nLIMIT $offset, 18446744073709551615";
00523 }
00524 $result = $this->query( $sql, $server );
00525
00526 if ( $result == false )
00527 {
00528 $this->reportQuery( 'eZMySQLDB', $sql, false, false );
00529 return false;
00530 }
00531
00532 $numRows = mysql_num_rows( $result );
00533 if ( $numRows > 0 )
00534 {
00535 if ( !is_string( $column ) )
00536 {
00537 eZDebug::accumulatorStart( 'mysql_loop', 'mysql_total', 'Looping result' );
00538 for ( $i=0; $i < $numRows; $i++ )
00539 {
00540 if ( $this->InputTextCodec )
00541 {
00542 $tmpRow = mysql_fetch_array( $result, MYSQL_ASSOC );
00543 $convRow = array();
00544 foreach( $tmpRow as $key => $row )
00545 {
00546 eZDebug::accumulatorStart( 'mysql_conversion', 'mysql_total', 'String conversion in mysql' );
00547 $convRow[$key] = $this->OutputTextCodec->convertString( $row );
00548 eZDebug::accumulatorStop( 'mysql_conversion' );
00549 }
00550 $retArray[$i + $offset] = $convRow;
00551 }
00552 else
00553 $retArray[$i + $offset] = mysql_fetch_array( $result, MYSQL_ASSOC );
00554 }
00555 eZDebug::accumulatorStop( 'mysql_loop' );
00556
00557 }
00558 else
00559 {
00560 eZDebug::accumulatorStart( 'mysql_loop', 'mysql_total', 'Looping result' );
00561 for ( $i=0; $i < $numRows; $i++ )
00562 {
00563 $tmp_row = mysql_fetch_array( $result, MYSQL_ASSOC );
00564 if ( $this->InputTextCodec )
00565 {
00566 eZDebug::accumulatorStart( 'mysql_conversion', 'mysql_total', 'String conversion in mysql' );
00567 $retArray[$i + $offset] = $this->OutputTextCodec->convertString( $tmp_row[$column] );
00568 eZDebug::accumulatorStop( 'mysql_conversion' );
00569 }
00570 else
00571 $retArray[$i + $offset] =& $tmp_row[$column];
00572 }
00573 eZDebug::accumulatorStop( 'mysql_loop' );
00574 }
00575 }
00576 }
00577 return $retArray;
00578 }
00579
00580 function subString( $string, $from, $len = null )
00581 {
00582 if ( $len == null )
00583 {
00584 return " substring( $string from $from ) ";
00585 }else
00586 {
00587 return " substring( $string from $from for $len ) ";
00588 }
00589 }
00590
00591 function concatString( $strings = array() )
00592 {
00593 $str = implode( "," , $strings );
00594 return " concat( $str ) ";
00595 }
00596
00597 function md5( $str )
00598 {
00599 return " MD5( $str ) ";
00600 }
00601
00602
00603
00604
00605 function supportedRelationTypeMask()
00606 {
00607 return EZ_DB_RELATION_TABLE_BIT;
00608 }
00609
00610
00611
00612
00613 function supportedRelationTypes()
00614 {
00615 return array( EZ_DB_RELATION_TABLE );
00616 }
00617
00618
00619
00620
00621 function relationCounts( $relationMask )
00622 {
00623 if ( $relationMask & EZ_DB_RELATION_TABLE_BIT )
00624 return $this->relationCount();
00625 else
00626 return 0;
00627 }
00628
00629
00630
00631
00632 function relationCount( $relationType = EZ_DB_RELATION_TABLE )
00633 {
00634 if ( $relationType != EZ_DB_RELATION_TABLE )
00635 {
00636 eZDebug::writeError( "Unsupported relation type '$relationType'", 'eZMySQLDB::relationCount' );
00637 return false;
00638 }
00639 $count = false;
00640 if ( $this->IsConnected )
00641 {
00642 $result = mysql_list_tables( $this->DB, $this->DBConnection );
00643 $count = mysql_num_rows( $result );
00644 mysql_free_result( $result );
00645 }
00646 return $count;
00647 }
00648
00649
00650
00651
00652 function relationList( $relationType = EZ_DB_RELATION_TABLE )
00653 {
00654 if ( $relationType != EZ_DB_RELATION_TABLE )
00655 {
00656 eZDebug::writeError( "Unsupported relation type '$relationType'", 'eZMySQLDB::relationList' );
00657 return false;
00658 }
00659 $tables = array();
00660 if ( $this->IsConnected )
00661 {
00662 $result = mysql_list_tables( $this->DB, $this->DBConnection );
00663 $count = mysql_num_rows( $result );
00664 for ( $i = 0; $i < $count; ++ $i )
00665 {
00666 $tables[] = mysql_tablename( $result, $i );
00667 }
00668 mysql_free_result( $result );
00669 }
00670 return $tables;
00671 }
00672
00673
00674
00675
00676 function eZTableList( $server = EZ_DB_SERVER_MASTER )
00677 {
00678 $tables = array();
00679 if ( $this->IsConnected )
00680 {
00681 if ( $this->UseSlaveServer && $server == EZ_DB_SERVER_SLAVE )
00682 {
00683 $connection = $this->DBConnection;
00684 $db = $this->SlaveDB;
00685 }
00686 else
00687 {
00688 $connection = $this->DBWriteConnection;
00689 $db = $this->DB;
00690 }
00691
00692 $result = mysql_list_tables( $db, $connection );
00693 $count = mysql_num_rows( $result );
00694 for ( $i = 0; $i < $count; ++ $i )
00695 {
00696 $tableName = mysql_tablename( $result, $i );
00697 if ( substr( $tableName, 0, 2 ) == 'ez' )
00698 {
00699 $tables[$tableName] = EZ_DB_RELATION_TABLE;
00700 }
00701 }
00702 mysql_free_result( $result );
00703 }
00704 return $tables;
00705 }
00706
00707
00708
00709
00710 function relationMatchRegexp( $relationType )
00711 {
00712 return "#^ez#";
00713 }
00714
00715
00716
00717
00718 function removeRelation( $relationName, $relationType )
00719 {
00720 $relationTypeName = $this->relationName( $relationType );
00721 if ( !$relationTypeName )
00722 {
00723 eZDebug::writeError( "Unknown relation type '$relationType'", 'eZMySQLDB::removeRelation' );
00724 return false;
00725 }
00726
00727 if ( $this->IsConnected )
00728 {
00729 $sql = "DROP $relationTypeName $relationName";
00730 return $this->query( $sql );
00731 }
00732 return false;
00733 }
00734
00735
00736
00737
00738 function lock( $table )
00739 {
00740 if ( $this->IsConnected )
00741 {
00742 if ( is_array( $table ) )
00743 {
00744 $lockQuery = "LOCK TABLES";
00745 $first = true;
00746 foreach( array_keys( $table ) as $tableKey )
00747 {
00748 if ( $first == true )
00749 $first = false;
00750 else
00751 $lockQuery .= ",";
00752 $lockQuery .= " " . $table[$tableKey]['table'] . " WRITE";
00753 }
00754 $this->query( $lockQuery );
00755 }
00756 else
00757 {
00758 $this->query( "LOCK TABLES $table WRITE" );
00759 }
00760 }
00761 }
00762
00763
00764
00765
00766 function unlock()
00767 {
00768 if ( $this->IsConnected )
00769 {
00770 $this->query( "UNLOCK TABLES" );
00771 }
00772 }
00773
00774
00775
00776
00777
00778 function beginQuery()
00779 {
00780 return $this->query("BEGIN WORK");
00781 }
00782
00783
00784
00785
00786
00787 function commitQuery()
00788 {
00789 return $this->query( "COMMIT" );
00790 }
00791
00792
00793
00794
00795
00796 function rollbackQuery()
00797 {
00798 return $this->query( "ROLLBACK" );
00799 }
00800
00801
00802
00803
00804 function lastSerialID( $table = false, $column = false )
00805 {
00806 if ( $this->IsConnected )
00807 {
00808 $id = mysql_insert_id( $this->DBWriteConnection );
00809 return $id;
00810 }
00811 else
00812 return false;
00813 }
00814
00815
00816
00817
00818 function escapeString( $str )
00819 {
00820 return mysql_real_escape_string( $str );
00821 }
00822
00823
00824
00825
00826 function close()
00827 {
00828 if ( $this->IsConnected )
00829 {
00830 mysql_close( $this->DBConnection );
00831 mysql_close( $this->DBWriteConnection );
00832 }
00833 }
00834
00835
00836
00837
00838 function createDatabase( $dbName )
00839 {
00840 if ( $this->DBConnection != false )
00841 {
00842 mysql_create_db( $dbName, $this->DBConnection );
00843 $this->setError();
00844 }
00845 }
00846
00847
00848
00849
00850 function setError()
00851 {
00852 if ( $this->DBConnection )
00853 {
00854 $this->ErrorMessage = mysql_error( $this->DBConnection );
00855 $this->ErrorNumber = mysql_errno( $this->DBConnection );
00856 }
00857 else
00858 {
00859 $this->ErrorMessage = mysql_error();
00860 $this->ErrorNumber = mysql_errno();
00861 }
00862 }
00863
00864
00865
00866
00867 function availableDatabases()
00868 {
00869 $databaseArray = mysql_list_dbs( $this->DBConnection );
00870
00871 if ( $this->errorNumber() != 0 )
00872 {
00873 return null;
00874 }
00875
00876 $databases = array();
00877 $i = 0;
00878 $numRows = mysql_num_rows( $databaseArray );
00879 if ( count( $numRows ) == 0 )
00880 {
00881 return false;
00882 }
00883
00884 $dbServerVersion = $this->databaseServerVersion();
00885 $dbServerMainVersion = $dbServerVersion['values'][0];
00886
00887 while ( $i < $numRows )
00888 {
00889
00890 $curDB = mysql_db_name( $databaseArray, $i );
00891 if ( strcasecmp( $curDB, 'mysql' ) != 0 &&
00892 ( $dbServerMainVersion < '5' || strcasecmp( $curDB, 'information_schema' ) != 0 ) )
00893 {
00894 $databases[] = $curDB;
00895 }
00896 ++$i;
00897 }
00898 return $databases;
00899 }
00900
00901
00902
00903
00904 function databaseServerVersion()
00905 {
00906 $versionInfo = mysql_get_server_info();
00907
00908 $versionArray = explode( '.', $versionInfo );
00909
00910 return array( 'string' => $versionInfo,
00911 'values' => $versionArray );
00912 }
00913
00914
00915
00916
00917 function databaseClientVersion()
00918 {
00919 $versionInfo = mysql_get_client_info();
00920
00921 $versionArray = explode( '.', $versionInfo );
00922
00923 return array( 'string' => $versionInfo,
00924 'values' => $versionArray );
00925 }
00926
00927
00928
00929
00930 function isCharsetSupported( $charset )
00931 {
00932 if ( $charset == 'utf-8' )
00933 {
00934 $versionInfo = $this->databaseServerVersion();
00935
00936
00937
00938
00939 return ( version_compare( $versionInfo['string'], '4.1.1' ) >= 0 );
00940 }
00941 else
00942 {
00943 return true;
00944 }
00945 }
00946
00947 var $CharsetMapping;
00948 var $TempTableList;
00949
00950
00951 }
00952
00953 ?>