Documentation TYPO3 par Ameos

mysql_wrappers.lib.php

00001 <?php
00002 /* $Id: mysql_wrappers.lib.php,v 2.2 2003/11/26 22:52:23 rabus Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 
00012 function PMA_mysql_dbname($result, $row, $field = FALSE) {
00013     if ($field != FALSE) {
00014         return PMA_convert_display_charset(mysql_dbname($result, $row, $field));
00015     } else {
00016         return PMA_convert_display_charset(mysql_dbname($result, $row));
00017     }
00018 }
00019 
00020 function PMA_mysql_error($id = FALSE) {
00021     if ($id != FALSE) {
00022         if (mysql_errno($id) != 0) {
00023             return PMA_convert_display_charset('#' . mysql_errno($id) . ' - ' . mysql_error($id));
00024         }
00025     } elseif (mysql_errno() != 0) {
00026         return PMA_convert_display_charset('#' . mysql_errno() . ' - ' . mysql_error());
00027     }
00028 
00029     return FALSE;
00030 }
00031 
00032 function PMA_mysql_fetch_array($result, $type = FALSE) {
00033     global $cfg, $allow_recoding, $charset, $convcharset;
00034 
00035     if ($type != FALSE) {
00036         $data = mysql_fetch_array($result, $type);
00037     } else {
00038         $data = mysql_fetch_array($result);
00039     }
00040     if (!(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) {
00041         /* No recoding -> return data as we got them */
00042         return $data;
00043     } else {
00044         $ret = array();
00045         $num = mysql_num_fields($result);
00046         $i = 0;
00047         for($i = 0; $i < $num; $i++) {
00048             $meta = mysql_fetch_field($result);
00049             $name = mysql_field_name($result, $i);
00050             if (!$meta) {
00051                 /* No meta information available -> we guess that it should be converted */
00052                 if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]);
00053                 if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]);
00054             } else {
00055                 /* Meta information available -> check type of field and convert it according to the type */
00056                 if ($meta->blob || stristr($meta->type, 'BINARY')) {
00057                     if (isset($data[$i])) $ret[$i] = $data[$i];
00058                     if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = $data[$name];
00059                 } else {
00060                     if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]);
00061                     if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]);
00062                 }
00063             }
00064         }
00065         return $ret;
00066     }
00067 }
00068 
00069 function PMA_mysql_fetch_field($result , $field_offset = FALSE) {
00070     if ($field_offset != FALSE) {
00071         return PMA_convert_display_charset(mysql_fetch_field($result, $field_offset));
00072     } else {
00073         return PMA_convert_display_charset(mysql_fetch_field($result));
00074     }
00075 }
00076 
00077 function PMA_mysql_fetch_row($result) {
00078     /* nijel: This is not optimal, but keeps us from duplicating code, if
00079      * speed really matters, duplicate here code from PMA_mysql_fetch_array
00080      * with removing rows working with associative array. */
00081     return PMA_mysql_fetch_array($result, MYSQL_NUM);
00082 }
00083 
00084 function PMA_mysql_field_flags($result, $field_offset) {
00085     return PMA_convert_display_charset(mysql_field_flags($result, $field_offset));
00086 }
00087 
00088 function PMA_mysql_field_name($result, $field_index) {
00089     return PMA_convert_display_charset(mysql_field_name($result, $field_index));
00090 }
00091 
00092 function PMA_mysql_field_type($result, $field_index) {
00093     return PMA_convert_display_charset(mysql_field_type($result, $field_index));
00094 }
00095 
00096 function PMA_mysql_query($query, $link_identifier = FALSE, $result_mode = FALSE) {
00097     if ($link_identifier != FALSE) {
00098         if ($result_mode != FALSE) {
00099             return mysql_query(PMA_convert_charset($query), $link_identifier, $result_mode);
00100         } else {
00101             return mysql_query(PMA_convert_charset($query), $link_identifier);
00102         }
00103     } else {
00104         return mysql_query(PMA_convert_charset($query));
00105     }
00106 }
00107 
00108 // mysql_list_tables() is deprecated, also we got report about weird results
00109 // under some circumstances
00110 
00111 function PMA_mysql_list_tables($database_name, $link_identifier = FALSE) {
00112     if ($link_identifier != FALSE) {
00113         return PMA_mysql_query('SHOW TABLES FROM ' . PMA_backquote(PMA_convert_charset($database_name)), $link_identifier);
00114     } else {
00115         return PMA_mysql_query('SHOW TABLES FROM ' . PMA_backquote(PMA_convert_charset($database_name)));
00116     }
00117 }
00118 
00119 // mysql_list_fields() is deprecated, also we got report about weird results
00120 // under some circumstances
00121 //
00122 // using SELECT * FROM db.table
00123 // lets us use functions like mysql_field_name() on the result set
00124 
00125 function PMA_mysql_list_fields_alternate($database_name, $table_name, $link_identifier = FALSE) {
00126     if ($link_identifier != FALSE) {
00127         $result = PMA_mysql_query('SHOW FIELDS FROM '
00128          . PMA_backquote(PMA_convert_charset($database_name)) . '.'
00129          . PMA_backquote(PMA_convert_charset($table_name)), $link_identifier);
00130     } else {
00131         $result = PMA_mysql_query('SHOW FIELDS FROM '
00132          . PMA_backquote(PMA_convert_charset($database_name)) . '.'
00133          . PMA_backquote(PMA_convert_charset($table_name)));
00134     }
00135 
00136     $fields = array();
00137     while ($row = PMA_mysql_fetch_array($result)) {
00138         $fields[] = $row;
00139     }
00140 
00141     return $fields;
00142 }
00143 
00144 function PMA_mysql_list_fields($database_name, $table_name, $link_identifier = FALSE) {
00145     if ($link_identifier != FALSE) {
00146         return mysql_list_fields(PMA_convert_charset($database_name), PMA_convert_charset($table_name), $link_identifier);
00147     } else {
00148         return mysql_list_fields(PMA_convert_charset($database_name), PMA_convert_charset($table_name));
00149     }
00150 }
00151 
00152 function PMA_mysql_result($result, $row, $field = FALSE) {
00153     if ($field != FALSE) {
00154         return PMA_convert_display_charset(mysql_result($result, $row, PMA_convert_charset($field)));
00155     } else {
00156         return PMA_convert_display_charset(mysql_result($result, $row));
00157     }
00158 }
00159 
00160 function PMA_mysql_select_db($database_name, $link_identifier = FALSE) {
00161     if ($link_identifier != FALSE) {
00162         return mysql_select_db(PMA_convert_charset($database_name), $link_identifier);
00163     } else {
00164         return mysql_select_db(PMA_convert_charset($database_name));
00165     }
00166 }
00167 
00168 function PMA_mysql_tablename($result, $i) {
00169     return PMA_convert_display_charset(mysql_tablename($result, $i));
00170 }
00171 
00172 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6