Files
phpmyadmin/libraries/dbi/mysql.dbi.lib.php
2004-01-17 01:47:36 +00:00

104 lines
2.9 KiB
PHP

<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Interface to the classic MySQL extension
*/
require_once('./libraries/charset_conversion.lib.php');
/**
* Loads the mysql extensions if it is not loaded yet
*/
if (!@function_exists('mysql_connect')) {
PMA_dl('mysql');
}
// check whether mysql is available
if (!@function_exists('mysql_connect')) {
require_once('./libraries/header_http.inc.php');
echo $strCantLoadMySQL . '<br />' . "\n"
. '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
exit;
}
// MySQL client API
if (!defined('PMA_MYSQL_CLIENT_API')) {
$client_api = explode('.', mysql_get_client_info());
define('PMA_MYSQL_CLIENT_API', (int)sprintf('%d%02d%02d', $client_api[0], $client_api[1], intval($client_api[2])));
unset($client_api);
}
function PMA_DBI_connect($user, $password) {
global $cfg, $php_errormsg;
$server_port = (empty($cfg['Server']['port']))
? ''
: ':' . $cfg['Server']['port'];
if (strtolower($cfg['Server']['connect_type']) == 'tcp') {
$cfg['Server']['socket'] = '';
}
$server_socket = (empty($cfg['Server']['socket']))
? ''
: ':' . $cfg['Server']['socket'];
if (PMA_MYSQL_CLIENT_API >= 32349) {
$client_flags = $cfg['Server']['compress'] && defined('MYSQL_CLIENT_COMPRESS') ? MYSQL_CLIENT_COMPRESS : 0;
}
if (empty($client_clags)) {
$connect_func = 'mysql_' . ($cfg['PersistentConnections'] ? 'p' : '') . 'connect';
$link = @$connect_func($cfg['Server']['host'] . $server_port . $server_socket, $user, $password);
} else {
if ($cfg['PersistentConnections']) {
$link = @mysql_pconnect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, $client_flags);
} else {
$link = @mysql_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, FALSE, $client_flags);
}
}
if (empty($link)) {
PMA_auth_fails();
} // end if
return $link;
}
function PMA_DBI_try_query($query, $link = '') {
if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
} else {
return FALSE;
}
}
return mysql_query(PMA_convert_charset($query), $link);
}
function PMA_DBI_getError($link = '') {
if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
} else {
return FALSE;
}
}
$error = mysql_errno($link);
if ($error) {
$error = mysql_errno($link);
if (!empty($error)) {
$error = '#' . ((string) $error) . ' - ' . PMA_convert_display_charset(mysql_error($link));
}
}
}
function PMA_DBI_close($link = '') {
if (empty($link)) {
$link = $GLOBALS['userlink'];
}
@mysql_close($link);
}
?>