3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Functions to wrap around MySQL database functions. This is basically made
8 * to allow charset conversion, but later may be useful for other stuff.
13 if (!defined('PMA_MYSQL_WRAPPERS_LIB_INCLUDED')){
14 define('PMA_MYSQL_WRAPPERS_LIB_INCLUDED', 1);
16 function PMA_mysql_dbname($result, $row, $field = FALSE) {
17 if ($field != FALSE) {
18 return PMA_convert_display_charset(mysql_dbname($result, $row, $field));
20 return PMA_convert_display_charset(mysql_dbname($result, $row));
24 function PMA_mysql_error($id = FALSE) {
26 if (mysql_errno($id) != 0) {
27 return PMA_convert_display_charset('#' . mysql_errno($id) . ' - ' . mysql_error($id));
29 } elseif (mysql_errno() != 0) {
30 return PMA_convert_display_charset('#' . mysql_errno() . ' - ' . mysql_error());
36 function PMA_mysql_fetch_array($result, $type = FALSE) {
37 global $cfg, $allow_recoding, $charset, $convcharset;
40 $data = mysql_fetch_array($result, $type);
42 $data = mysql_fetch_array($result);
44 if (!(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) {
45 /* No recoding -> return data as we got them */
49 $num = mysql_num_fields($result);
51 for($i = 0; $i < $num; $i++
) {
52 $meta = mysql_fetch_field($result);
53 $name = mysql_field_name($result, $i);
55 /* No meta information available -> we guess that it should be converted */
56 if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]);
57 if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]);
59 /* Meta information available -> check type of field and convert it according to the type */
60 if ($meta->blob ||
eregi('BINARY', $meta->type
)) {
61 if (isset($data[$i])) $ret[$i] = $data[$i];
62 if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = $data[$name];
64 if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]);
65 if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]);
73 function PMA_mysql_fetch_field($result , $field_offset = FALSE) {
74 if ($field_offset != FALSE) {
75 return PMA_convert_display_charset(mysql_fetch_field($result, $field_offset));
77 return PMA_convert_display_charset(mysql_fetch_field($result));
81 function PMA_mysql_fetch_row($result) {
82 /* nijel: This is not optimal, but keeps us from duplicating code, if
83 * speed really matters, duplicate here code from PMA_mysql_fetch_array
84 * with removing rows working with associative array. */
85 return PMA_mysql_fetch_array($result, MYSQL_NUM
);
88 function PMA_mysql_field_flags($result, $field_offset) {
89 return PMA_convert_display_charset(mysql_field_flags($result, $field_offset));
92 function PMA_mysql_field_name($result, $field_index) {
93 return PMA_convert_display_charset(mysql_field_name($result, $field_index));
96 function PMA_mysql_field_type($result, $field_index) {
97 return PMA_convert_display_charset(mysql_field_type($result, $field_index));
100 function PMA_mysql_list_fields($database_name, $table_name, $link_identifier = FALSE) {
101 if ($link_identifier != FALSE) {
102 return mysql_list_fields(PMA_convert_charset($database_name), PMA_convert_charset($table_name), $link_identifier);
104 return mysql_list_fields(PMA_convert_charset($database_name), PMA_convert_charset($table_name));
108 function PMA_mysql_list_tables($database_name, $link_identifier = FALSE) {
109 if ($link_identifier != FALSE) {
110 return mysql_list_tables(PMA_convert_charset($database_name), $link_identifier);
112 return mysql_list_tables(PMA_convert_charset($database_name));
116 function PMA_mysql_query($query, $link_identifier = FALSE, $result_mode = FALSE) {
117 if ($link_identifier != FALSE) {
118 if ($result_mode != FALSE) {
119 return mysql_query(PMA_convert_charset($query), $link_identifier, $result_mode);
121 return mysql_query(PMA_convert_charset($query), $link_identifier);
124 return mysql_query(PMA_convert_charset($query));
128 function PMA_mysql_result($result, $row, $field = FALSE) {
129 if ($field != FALSE) {
130 return PMA_convert_display_charset(mysql_result($result, $row, PMA_convert_charset($field)));
132 return PMA_convert_display_charset(mysql_result($result, $row));
136 function PMA_mysql_select_db($database_name, $link_identifier = FALSE) {
137 if ($link_identifier != FALSE) {
138 return mysql_select_db(PMA_convert_charset($database_name), $link_identifier);
140 return mysql_select_db(PMA_convert_charset($database_name));
144 function PMA_mysql_tablename($result, $i) {
145 return PMA_convert_display_charset(mysql_tablename($result, $i));
149 } // PMA_MYSQL_WRAPPERS_LIB_INCLUDED