Documentation TYPO3 par Ameos |
00001 <?php 00002 /* $Id: database_interface.lib.php,v 2.20 2005/08/23 11:56:52 nijel Exp $ */ 00003 // vim: expandtab sw=4 ts=4 sts=4: 00004 00008 // PMA_DBI_try_query() 00009 define('PMA_DBI_QUERY_STORE', 1); // Force STORE_RESULT method, ignored by classic MySQL. 00010 define('PMA_DBI_QUERY_UNBUFFERED', 2); // Do not read whole query 00011 // PMA_DBI_get_variable() 00012 define('PMA_DBI_GETVAR_SESSION', 1); 00013 define('PMA_DBI_GETVAR_GLOBAL', 2); 00014 00018 require_once('./libraries/dbi/' . $cfg['Server']['extension'] . '.dbi.lib.php'); 00019 00023 function PMA_DBI_query($query, $link = NULL, $options = 0) { 00024 $res = PMA_DBI_try_query($query, $link, $options) 00025 or PMA_mysqlDie(PMA_DBI_getError($link), $query); 00026 return $res; 00027 } 00028 00029 function PMA_DBI_get_dblist($link = NULL) { 00030 if (empty($link)) { 00031 if (isset($GLOBALS['userlink'])) { 00032 $link = $GLOBALS['userlink']; 00033 } else { 00034 return FALSE; 00035 } 00036 } 00037 $res = PMA_DBI_try_query('SHOW DATABASES;', $link); 00038 $dbs_array = array(); 00039 while ($row = PMA_DBI_fetch_row($res)) { 00040 00041 // Before MySQL 4.0.2, SHOW DATABASES could send the 00042 // whole list, so check if we really have access: 00043 //if (PMA_MYSQL_CLIENT_API < 40002) { 00044 // Better check the server version, in case the client API 00045 // is more recent than the server version 00046 00047 if (PMA_MYSQL_INT_VERSION < 40002) { 00048 $dblink = @PMA_DBI_select_db($row[0], $link); 00049 if (!$dblink) { 00050 continue; 00051 } 00052 } 00053 $dbs_array[] = $row[0]; 00054 } 00055 PMA_DBI_free_result($res); 00056 unset($res); 00057 00058 return $dbs_array; 00059 } 00060 00061 function PMA_DBI_get_tables($database, $link = NULL) { 00062 $result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($database) . ';', NULL, PMA_DBI_QUERY_STORE); 00063 $tables = array(); 00064 while (list($current) = PMA_DBI_fetch_row($result)) { 00065 $tables[] = $current; 00066 } 00067 PMA_DBI_free_result($result); 00068 00069 return $tables; 00070 } 00071 00072 function PMA_DBI_get_tables_full($database, $link = NULL) { 00073 $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($database) . ';', NULL, PMA_DBI_QUERY_STORE); 00074 $tables = array(); 00075 while ($row = PMA_DBI_fetch_assoc($result)) { 00076 $tables[$row['Name']] = $row; 00077 } 00078 PMA_DBI_free_result($result); 00079 return $tables; 00080 } 00081 00082 function PMA_DBI_get_fields($database, $table, $link = NULL) { 00083 if (empty($link)) { 00084 if (isset($GLOBALS['userlink'])) { 00085 $link = $GLOBALS['userlink']; 00086 } else { 00087 return FALSE; 00088 } 00089 } 00090 // here we use a try_query because when coming from 00091 // tbl_create + tbl_properties.inc.php, the table does not exist 00092 $result = PMA_DBI_try_query('SHOW FULL FIELDS FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table), $link); 00093 00094 if (!$result) { 00095 return FALSE; 00096 } 00097 00098 $fields = array(); 00099 while ($row = PMA_DBI_fetch_assoc($result)) { 00100 $fields[] = $row; 00101 } 00102 00103 return $fields; 00104 } 00105 00106 function PMA_DBI_get_variable($var, $type = PMA_DBI_GETVAR_SESSION, $link = NULL) { 00107 if ($link === NULL) { 00108 if (isset($GLOBALS['userlink'])) { 00109 $link = $GLOBALS['userlink']; 00110 } else { 00111 return FALSE; 00112 } 00113 } 00114 if (PMA_MYSQL_INT_VERSION < 40002) { 00115 $type = 0; 00116 } 00117 switch ($type) { 00118 case PMA_DBI_GETVAR_SESSION: 00119 $modifier = ' SESSION'; 00120 break; 00121 case PMA_DBI_GETVAR_GLOBAL: 00122 $modifier = ' GLOBAL'; 00123 break; 00124 default: 00125 $modifier = ''; 00126 } 00127 $res = PMA_DBI_query('SHOW' . $modifier . ' VARIABLES LIKE \'' . $var . '\';', $link); 00128 $row = PMA_DBI_fetch_row($res); 00129 PMA_DBI_free_result($res); 00130 if (empty($row)) { 00131 return FALSE; 00132 } else { 00133 return $row[0] == $var ? $row[1] : FALSE; 00134 } 00135 } 00136 00137 function PMA_DBI_postConnect($link, $is_controluser = FALSE) { 00138 global $collation_connection, $charset_connection; 00139 if (!defined('PMA_MYSQL_INT_VERSION')) { 00140 $result = PMA_DBI_query('SELECT VERSION() AS version', $link, PMA_DBI_QUERY_STORE); 00141 if ($result != FALSE && @PMA_DBI_num_rows($result) > 0) { 00142 $row = PMA_DBI_fetch_row($result); 00143 $match = explode('.', $row[0]); 00144 PMA_DBI_free_result($result); 00145 } 00146 if (!isset($row)) { 00147 define('PMA_MYSQL_INT_VERSION', 32332); 00148 define('PMA_MYSQL_STR_VERSION', '3.23.32'); 00149 } else{ 00150 define('PMA_MYSQL_INT_VERSION', (int)sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2]))); 00151 define('PMA_MYSQL_STR_VERSION', $row[0]); 00152 unset($result, $row, $match); 00153 } 00154 } 00155 00156 if (PMA_MYSQL_INT_VERSION >= 40100) { 00157 00158 // If $lang is defined and we are on MySQL >= 4.1.x, 00159 // we auto-switch the lang to its UTF-8 version (if it exists and user didn't force language) 00160 if (!empty($GLOBALS['lang']) && (substr($GLOBALS['lang'], -5) != 'utf-8') && !isset($GLOBALS['cfg']['Lang'])) { 00161 $lang_utf_8_version = substr($GLOBALS['lang'], 0, strpos($GLOBALS['lang'], '-')) . '-utf-8'; 00162 if (!empty($GLOBALS['available_languages'][$lang_utf_8_version])) { 00163 $GLOBALS['lang'] = $lang_utf_8_version; 00164 $GLOBALS['charset'] = $charset = 'utf-8'; 00165 } 00166 } 00167 00168 // and we remove the non-UTF-8 choices to avoid confusion 00169 if (!defined('PMA_REMOVED_NON_UTF_8')) { 00170 $tmp_available_languages = $GLOBALS['available_languages']; 00171 $GLOBALS['available_languages'] = array(); 00172 foreach ($tmp_available_languages AS $tmp_lang => $tmp_lang_data) { 00173 if (substr($tmp_lang, -5) == 'utf-8') { 00174 $GLOBALS['available_languages'][$tmp_lang] = $tmp_lang_data; 00175 } 00176 } // end foreach 00177 unset($tmp_lang, $tmp_lang_data, $tmp_available_languages); 00178 define('PMA_REMOVED_NON_UTF_8',1); 00179 } 00180 00181 $mysql_charset = $GLOBALS['mysql_charset_map'][$GLOBALS['charset']]; 00182 if ($is_controluser || empty($collation_connection) || (strpos($collation_connection, '_') ? substr($collation_connection, 0, strpos($collation_connection, '_')) : $collation_connection) == $mysql_charset) { 00183 PMA_DBI_query('SET NAMES ' . $mysql_charset . ';', $link, PMA_DBI_QUERY_STORE); 00184 } else { 00185 PMA_DBI_query('SET CHARACTER SET ' . $mysql_charset . ';', $link, PMA_DBI_QUERY_STORE); 00186 } 00187 if (!empty($collation_connection)) { 00188 PMA_DBI_query('SET collation_connection = \'' . $collation_connection . '\';', $link, PMA_DBI_QUERY_STORE); 00189 } 00190 if (!$is_controluser) { 00191 $collation_connection = PMA_DBI_get_variable('collation_connection', PMA_DBI_GETVAR_SESSION, $link); 00192 $charset_connection = PMA_DBI_get_variable('character_set_connection', PMA_DBI_GETVAR_SESSION, $link); 00193 } 00194 00195 // Add some field types to the list 00196 // (we pass twice here; feel free to code something better :) 00197 if (!defined('PMA_ADDED_FIELD_TYPES')) { 00198 $GLOBALS['cfg']['ColumnTypes'][] = 'BINARY'; 00199 $GLOBALS['cfg']['ColumnTypes'][] = 'VARBINARY'; 00200 define('PMA_ADDED_FIELD_TYPES',1); 00201 } 00202 00203 } else { 00204 require_once('./libraries/charset_conversion.lib.php'); 00205 } 00206 } 00207 00208 ?>