function PMA_DBI_connect($user, $password, $is_controluser = FALSE) { 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_PHP_INT_VERSION >= 40300 && PMA_MYSQL_CLIENT_API >= 32349) { $client_flags = $cfg['Server']['compress'] && defined('MYSQL_CLIENT_COMPRESS') ? MYSQL_CLIENT_COMPRESS : 0; // always use CLIENT_LOCAL_FILES as defined in mysql_com.h // for the case where the client library was not compiled // with --enable-local-infile $client_flags |= 128; } $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? NULL : $client_flags); // Retry with empty password if we're allowed to if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags); } if (empty($link)) { PMA_auth_fails(); } // end if PMA_DBI_postConnect($link, $is_controluser); return $link; }
function PMA_DBI_connect($user, $password, $is_controluser = false) { 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']; $client_flags = 0; // always use CLIENT_LOCAL_FILES as defined in mysql_com.h // for the case where the client library was not compiled // with --enable-local-infile $client_flags |= 128; /* Optionally compress connection */ if (defined('MYSQL_CLIENT_COMPRESS') && $cfg['Server']['compress']) { $client_flags |= MYSQL_CLIENT_COMPRESS; } /* Optionally enable SSL */ if (defined('MYSQL_CLIENT_SSL') && $cfg['Server']['ssl']) { $client_flags |= MYSQL_CLIENT_SSL; } $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? NULL : $client_flags); // Retry with empty password if we're allowed to if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags); } if (empty($link)) { if ($is_controluser) { trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); return false; } PMA_log_user($user, 'mysql-denied'); PMA_auth_fails(); } // end if PMA_DBI_postConnect($link, $is_controluser); return $link; }
/** * @param string $user mysql user name * @param string $password mysql user password * @param boolean $is_controluser * @param array $server host/port/socket/persistant * @param boolean $auxiliary_connection (when true, don't go back to login if connection fails) * @return mixed false on error or a mysqli object on success */ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false) { global $cfg, $php_errormsg; if ($server) { $server_port = empty($server['port']) ? '' : ':' . (int) $server['port']; $server_socket = empty($server['socket']) ? '' : ':' . $server['socket']; $server_persistant = empty($server['persistant']) ? false : true; } else { $server_port = empty($cfg['Server']['port']) ? '' : ':' . (int) $cfg['Server']['port']; $server_socket = empty($cfg['Server']['socket']) ? '' : ':' . $cfg['Server']['socket']; } if (strtolower($cfg['Server']['connect_type']) == 'tcp') { $cfg['Server']['socket'] = ''; } $client_flags = 0; // always use CLIENT_LOCAL_FILES as defined in mysql_com.h // for the case where the client library was not compiled // with --enable-local-infile $client_flags |= 128; /* Optionally compress connection */ if (defined('MYSQL_CLIENT_COMPRESS') && $cfg['Server']['compress']) { $client_flags |= MYSQL_CLIENT_COMPRESS; } /* Optionally enable SSL */ if (defined('MYSQL_CLIENT_SSL') && $cfg['Server']['ssl']) { $client_flags |= MYSQL_CLIENT_SSL; } if (!$server) { $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? NULL : $client_flags); // Retry with empty password if we're allowed to if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags); } } else { if (!isset($server['host'])) { $link = PMA_DBI_real_connect($server_socket, $user, $password, NULL, $server_persistant); } else { $link = PMA_DBI_real_connect($server['host'] . $server_port . $server_socket, $user, $password, NULL, $server_persistant); } } if (empty($link)) { if ($is_controluser) { trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); return false; } // we could be calling PMA_DBI_connect() to connect to another // server, for example in the Synchronize feature, so do not // go back to main login if it fails if (!$auxiliary_connection) { PMA_log_user($user, 'mysql-denied'); PMA_auth_fails(); } else { return false; } } // end if if (!$server) { PMA_DBI_postConnect($link, $is_controluser); } return $link; }
/** * connects to the database server * * @param string $user mysql user name * @param string $password mysql user password * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent * @param bool $auxiliary_connection (when true, don't go back to login if * connection fails) * * @return mixed false on error or a mysqli object on success */ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false) { global $cfg; if ($server) { $server_port = empty($server['port']) ? false : (int) $server['port']; $server_socket = empty($server['socket']) ? '' : $server['socket']; $server['host'] = empty($server['host']) ? 'localhost' : $server['host']; } else { $server_port = empty($cfg['Server']['port']) ? false : (int) $cfg['Server']['port']; $server_socket = empty($cfg['Server']['socket']) ? null : $cfg['Server']['socket']; } // NULL enables connection to the default socket $link = mysqli_init(); mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true); $client_flags = 0; /* Optionally compress connection */ if ($cfg['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) { $client_flags |= MYSQLI_CLIENT_COMPRESS; } /* Optionally enable SSL */ if ($cfg['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) { $client_flags |= MYSQLI_CLIENT_SSL; } if (!$server) { $return_value = @PMA_DBI_real_connect($link, $cfg['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags); // Retry with empty password if we're allowed to if ($return_value == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) { $return_value = @PMA_DBI_real_connect($link, $cfg['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags); } } else { $return_value = @PMA_DBI_real_connect($link, $server['host'], $user, $password, false, $server_port, $server_socket); } if ($return_value == false) { if ($is_controluser) { trigger_error(__('Connection for controluser as defined in your configuration failed.'), E_USER_WARNING); return false; } // we could be calling PMA_DBI_connect() to connect to another // server, for example in the Synchronize feature, so do not // go back to main login if it fails if (!$auxiliary_connection) { PMA_log_user($user, 'mysql-denied'); global $auth_plugin; $auth_plugin->authFails(); } else { return false; } } else { PMA_DBI_postConnect($link, $is_controluser); } return $link; }
/** * connects to the database server * * @param string $user drizzle user name * @param string $password drizzle user password * @param bool $is_controluser * @param array $server host/port/socket * @param bool $auxiliary_connection (when true, don't go back to login if connection fails) * @return mixed false on error or a mysqli object on success */ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false) { global $cfg; if ($server) { $server_port = empty($server['port']) ? false : (int) $server['port']; $server_socket = empty($server['socket']) ? '' : $server['socket']; $server['host'] = empty($server['host']) ? 'localhost' : $server['host']; } else { $server_port = empty($cfg['Server']['port']) ? false : (int) $cfg['Server']['port']; $server_socket = empty($cfg['Server']['socket']) ? null : $cfg['Server']['socket']; } if (strtolower($GLOBALS['cfg']['Server']['connect_type']) == 'tcp') { $GLOBALS['cfg']['Server']['socket'] = ''; } $drizzle = new PMA_Drizzle(); $client_flags = 0; /* Optionally compress connection */ if ($GLOBALS['cfg']['Server']['compress']) { $client_flags |= DRIZZLE_CAPABILITIES_COMPRESS; } /* Optionally enable SSL */ if ($GLOBALS['cfg']['Server']['ssl']) { $client_flags |= DRIZZLE_CAPABILITIES_SSL; } if (!$server) { $link = @PMA_DBI_real_connect($drizzle, $cfg['Server']['host'], $server_port, $server_socket, $user, $password, false, $client_flags); // Retry with empty password if we're allowed to if ($link == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) { $link = @PMA_DBI_real_connect($drizzle, $cfg['Server']['host'], $server_port, $server_socket, $user, null, false, $client_flags); } } else { $link = @PMA_DBI_real_connect($drizzle, $server['host'], $server_port, $server_socket, $user, $password); } if ($link == false) { if ($is_controluser) { trigger_error(__('Connection for controluser as defined in your configuration failed.'), E_USER_WARNING); return false; } // we could be calling PMA_DBI_connect() to connect to another // server, for example in the Synchronize feature, so do not // go back to main login if it fails if (!$auxiliary_connection) { PMA_log_user($user, 'drizzle-denied'); PMA_auth_fails(); } else { return false; } } else { PMA_DBI_postConnect($link, $is_controluser); } return $link; }