Documentation TYPO3 par Ameos

mysql.dbi.lib.php

00001 <?php
00002 /* $Id: mysql.dbi.lib.php,v 2.37 2005/03/24 20:57:00 rabus Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00012 if (!@function_exists('mysql_connect')) {
00013     PMA_dl('mysql');
00014 }
00015 
00016 // check whether mysql is available
00017 if (!@function_exists('mysql_connect')) {
00018     require_once('./libraries/header_http.inc.php');
00019     echo sprintf($strCantLoad, 'mysql') . '<br />' . "\n"
00020          . '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
00021     exit;
00022 }
00023 
00024 // MySQL client API
00025 if (!defined('PMA_MYSQL_CLIENT_API')) {
00026     if (function_exists('mysql_get_client_info')) {
00027         $client_api = explode('.', mysql_get_client_info());
00028         define('PMA_MYSQL_CLIENT_API', (int)sprintf('%d%02d%02d', $client_api[0], $client_api[1], intval($client_api[2])));
00029         unset($client_api);
00030     } else {
00031         define('PMA_MYSQL_CLIENT_API', 32332); // always expect the worst...
00032     }
00033 }
00034 
00035 function PMA_DBI_connect($user, $password, $is_controluser = FALSE) {
00036     global $cfg, $php_errormsg;
00037 
00038     $server_port   = (empty($cfg['Server']['port']))
00039                    ? ''
00040                    : ':' . $cfg['Server']['port'];
00041 
00042     if (strtolower($cfg['Server']['connect_type']) == 'tcp') {
00043         $cfg['Server']['socket'] = '';
00044     }
00045 
00046     $server_socket = (empty($cfg['Server']['socket']))
00047                    ? ''
00048                    : ':' . $cfg['Server']['socket'];
00049 
00050     if (PMA_PHP_INT_VERSION >= 40300 && PMA_MYSQL_CLIENT_API >= 32349) {
00051         $client_flags = $cfg['Server']['compress'] && defined('MYSQL_CLIENT_COMPRESS') ? MYSQL_CLIENT_COMPRESS : 0;
00052         // always use CLIENT_LOCAL_FILES as defined in mysql_com.h
00053         // for the case where the client library was not compiled
00054         // with --enable-local-infile
00055         $client_flags |= 128;
00056     }
00057 
00058     if (empty($client_flags)) {
00059         $connect_func = 'mysql_' . ($cfg['PersistentConnections'] ? 'p' : '') . 'connect';
00060         $link = @$connect_func($cfg['Server']['host'] . $server_port . $server_socket, $user, $password);
00061     } else {
00062         if ($cfg['PersistentConnections']) {
00063             $link = @mysql_pconnect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, $client_flags);
00064         } else {
00065             $link = @mysql_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, FALSE, $client_flags);
00066         }
00067     }
00068 
00069     if (empty($link)) {
00070         PMA_auth_fails();
00071     } // end if
00072     
00073     PMA_DBI_postConnect($link, $is_controluser);
00074 
00075     return $link;
00076 }
00077 
00078 function PMA_DBI_select_db($dbname, $link = NULL) {
00079     if (empty($link)) {
00080         if (isset($GLOBALS['userlink'])) {
00081             $link = $GLOBALS['userlink'];
00082         } else {
00083             return FALSE;
00084         }
00085     }
00086     if (PMA_MYSQL_INT_VERSION < 40100) {
00087         $dbname = PMA_convert_charset($dbname);
00088     }
00089     return mysql_select_db($dbname, $link);
00090 }
00091 
00092 function PMA_DBI_try_query($query, $link = NULL, $options = 0) {
00093     if (empty($link)) {
00094         if (isset($GLOBALS['userlink'])) {
00095             $link = $GLOBALS['userlink'];
00096         } else {
00097             return FALSE;
00098         }
00099     }
00100     if (defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION < 40100) {
00101         $query = PMA_convert_charset($query);
00102     }
00103     if ($options == ($options | PMA_DBI_QUERY_STORE)) {
00104         return @mysql_query($query, $link);
00105     } elseif ($options == ($options | PMA_DBI_QUERY_UNBUFFERED)) {
00106         return @mysql_unbuffered_query($query, $link);
00107     } else {
00108         return @mysql_query($query, $link);
00109     }
00110 }
00111 
00112 // The following function is meant for internal use only.
00113 // Do not call it from outside this library!
00114 function PMA_mysql_fetch_array($result, $type = FALSE) {
00115     global $cfg, $allow_recoding, $charset, $convcharset;
00116 
00117     if ($type != FALSE) {
00118         $data = mysql_fetch_array($result, $type);
00119     } else {
00120         $data = mysql_fetch_array($result);
00121     }
00122 
00123     /* No data returned => do not touch it */
00124     if (! $data) return $data;
00125     
00126     if (!defined('PMA_MYSQL_INT_VERSION') || PMA_MYSQL_INT_VERSION >= 40100
00127         || !(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) {
00128         /* No recoding -> return data as we got them */
00129         return $data;
00130     } else {
00131         $ret = array();
00132         $num = mysql_num_fields($result);
00133         $i = 0;
00134         for ($i = 0; $i < $num; $i++) {
00135             $name = mysql_field_name($result, $i);
00136             $flags = mysql_field_flags($result, $i);
00137             /* Field is BINARY (either marked manually, or it is BLOB) => do not convert it */
00138             if (stristr($flags, 'BINARY')) {
00139                 if (isset($data[$i])) $ret[$i] = $data[$i];
00140                 if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = $data[$name];
00141             } else {
00142                 if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]);
00143                 if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]);
00144             }
00145         }
00146         return $ret;
00147     }
00148 }
00149 
00150 function PMA_DBI_fetch_array($result) {
00151     return PMA_mysql_fetch_array($result);
00152 }
00153 
00154 function PMA_DBI_fetch_assoc($result) {
00155     return PMA_mysql_fetch_array($result, MYSQL_ASSOC);
00156 }
00157 
00158 function PMA_DBI_fetch_row($result) {
00159     return PMA_mysql_fetch_array($result, MYSQL_NUM);
00160 }
00161 
00162 function PMA_DBI_free_result($result) {
00163     if (!is_bool($result)) {
00164         return mysql_free_result($result);
00165     } else {
00166         return 0;
00167     }
00168 }
00169 
00170 function PMA_DBI_getError($link = NULL) {
00171     unset($GLOBALS['errno']); 
00172     if (empty($link)) {
00173         if (isset($GLOBALS['userlink'])) {
00174             $link = $GLOBALS['userlink'];
00175 
00176 // Do not stop now. On the initial connection, we don't have a $link,
00177 // we don't have a $GLOBALS['userlink'], but we can catch the error code
00178 //        } else {
00179 //            return FALSE;
00180        }
00181     }
00182 
00183     if (mysql_errno()) {
00184         $error = mysql_errno();
00185         $error_message = mysql_error();
00186     } elseif ($link) {
00187         $error = mysql_errno($link);
00188         $error_message = mysql_error($link);
00189     }
00190 
00191     // keep the error number for further check after the call to PMA_DBI_getError() 
00192     if (isset($error) && $error) {
00193         $GLOBALS['errno'] = $error;
00194     } else {
00195         return FALSE;
00196     }
00197 
00198 // Some errors messages cannot be obtained by mysql_error()
00199     if ($error && $error == 2002) {
00200         $error = '#' . ((string) $error) . ' - ' . $GLOBALS['strServerNotResponding'] . ' ' . $GLOBALS['strSocketProblem'];
00201     } elseif ($error && $error == 2003) {
00202         $error = '#' . ((string) $error) . ' - ' . $GLOBALS['strServerNotResponding'];
00203     } elseif ($error && defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100) {
00204         $error = '#' . ((string) $error) . ' - ' . $error_message;
00205     } elseif ($error) {
00206         $error = '#' . ((string) $error) . ' - ' . PMA_convert_display_charset($error_message);
00207     }
00208     return $error;
00209 }
00210 
00211 function PMA_DBI_close($link = NULL) {
00212     if (empty($link)) {
00213         if (isset($GLOBALS['userlink'])) {
00214             $link = $GLOBALS['userlink'];
00215         } else {
00216             return FALSE;
00217         }
00218     }
00219     return @mysql_close($link);
00220 }
00221 
00222 function PMA_DBI_num_rows($result) {
00223     if (!is_bool($result)) {
00224         return mysql_num_rows($result);
00225     } else {
00226         return 0;
00227     }
00228 }
00229 
00230 function PMA_DBI_insert_id($link = NULL) {
00231     if (empty($link)) {
00232         if (isset($GLOBALS['userlink'])) {
00233             $link = $GLOBALS['userlink'];
00234         } else {
00235             return FALSE;
00236         }
00237     }
00238     return mysql_insert_id($link);
00239 }
00240 
00241 function PMA_DBI_affected_rows($link = NULL) {
00242     if (empty($link)) {
00243         if (isset($GLOBALS['userlink'])) {
00244             $link = $GLOBALS['userlink'];
00245         } else {
00246             return FALSE;
00247         }
00248     }
00249     return mysql_affected_rows($link);
00250 }
00251 
00252 function PMA_DBI_get_fields_meta($result) {
00253     $fields       = array();
00254     $num_fields   = mysql_num_fields($result);
00255     for ($i = 0; $i < $num_fields; $i++) {
00256         $fields[] = PMA_convert_display_charset(mysql_fetch_field($result, $i));
00257     }
00258     return $fields;
00259 }
00260 
00261 function PMA_DBI_num_fields($result) {
00262     return mysql_num_fields($result);
00263 }
00264 
00265 function PMA_DBI_field_len($result, $i) {
00266     return mysql_field_len($result, $i);
00267 }
00268 
00269 function PMA_DBI_field_name($result, $i) {
00270     return mysql_field_name($result, $i);
00271 }
00272 
00273 function PMA_DBI_field_flags($result, $i) {
00274     return PMA_convert_display_charset(mysql_field_flags($result, $i));
00275 }
00276 
00277 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6