安装magento,获取数据库连接错误。 [英] Installing magento, get database connection error.

查看:160
本文介绍了安装magento,获取数据库连接错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装magento到我的网络主机,在安装期间我得到数据库连接错误我输入所有的值正确(已联系我的网站托管,以确保,因为我这里的遗憾)他们说, magento论坛的额外支持。我找不到修复。任何想法/帮助将是非常赞赏。

I am trying to install magento onto my webhost, during install i get "database connection error" i have input all the values correctly (have contacted my webhost to be sure as I am stumped at this point) they said to refer to magento forums for extra support. I cannot find a fix. Any ideas / help would be MUCH appreciated.

推荐答案

尝试此脚本测试您的连接并报告实际的MySQL错误。可能有用的是确定您提供的凭据是否有效,或者流程的哪一部分失败。由于您在远程Webhost上使用它,我建议您对数据库用户名和密码进行硬编码,以避免在开放的Internet上清除它们。

Try this script which tests your connection and reports the actual MySQL error. It might be useful to determine whether the credentials you were given will work, or which part of the process is failing. Since you are using it on a remote webhost I recommend you hard-code the database username and password to avoid passing them in clear over the open Internet.

(注意:我自己的工作 - 脚本来自webune.com)

(Note: Not my own work - script comes from webune.com)

<?php
###################################### C O P Y R I G H T S ####################################
# THIS SCRIPT IS DISTRIBUTED BY WEBUNE.COM UNDER LICENSE UNDER THE GPL RULES
# PLEASE DO NOT REMOVE THIS MESSAGE IN SUPPORT OF OUR HARD WORK TO CONTINUE TO PROVIDE FREE SUPPORT
###############################################################################################
# OK, HERE WE GO
# Use this varialble if you are using an installation script
$step = $_GET['step'];
if (!$step) {
    $page_title = 'Form';
}
else{
    $page_title = 'Test MySQL step '.$step;
}
############## BEGIN FUNCTIONS ##############################
# FUNCTION TO TEST USERNAME AND PASSWORD IN MYSQL HOST
function db_connect($server, $username, $password, $link = 'db_link') {
    global $$link, $db_error;
    $db_error = false;
    if (!$server) {
        $db_error = 'No Server selected.';
        return false;
    }
    $$link = @mysql_connect($server, $username, $password) or $db_error = mysql_error();
    return $$link;
}
# FUNCTION TO SELECT DATABASE ACCESS
function db_select_db($database) {
    echo mysql_error();
    return mysql_select_db($database);
}
# FUNCTION TO TEST DATABASE ACCESS
function db_test_create_db_permission($database) {
    global $db_error;
    $db_created = false;
    $db_error = false;
    if (!$database) {
        $db_error = 'No Database selected.';
        return false;
    }
    if ($db_error) {
        return false;
    } else {
        if (!@db_select_db($database)) {
            $db_error = mysql_error();
            return false;
        }else {
            return true;
        }
    return true;
    }
}

function step1 ($error) {
    echo '<h1 style="color:#FF0000">'.$error.'</h1><hr>';
?>
<form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>?step=2">
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><div align="right">mysql hostname:</div></td>
<td><input name="server" type="text" value="<?php echo $_REQUEST['server']; ?>">
(usually &quot;localhost&quot; or enter IP Address of MySQL Server)</td>
</tr>
<tr>
<td><div align="right">mysql username:</div></td>
<td><input type="text" name="username" value="<?php echo $_REQUEST['username']; ?>"></td>
</tr>
<tr>
<td><div align="right">mysql username password:</div></td>
<td><input type="text" name="password" value="<?php echo $_REQUEST['password']; ?>"></td>
</tr>
<tr>
<td><div align="right">mysql database name:</div></td>
<td><input type="text" name="database" value="<?php echo $_REQUEST['database']; ?>"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
<?php
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Webune MYSQL TEST - <?php echo $page_title; ?></title>
</head>
<body>
<h1><?php echo $page_title; ?></h1>
<?php
############## END FUNCTIONS ##############################
switch ($step) {
    case '2':
        if ($_REQUEST['server']) {
    $db = array();
    $db['DB_SERVER'] = trim(stripslashes($_REQUEST['server']));
    $db['DB_SERVER_USERNAME'] = trim(stripslashes($_REQUEST['username']));
    $db['DB_SERVER_PASSWORD'] = trim(stripslashes($_REQUEST['password']));
    $db['DB_DATABASE'] = trim(stripslashes($_REQUEST['database']));
    $db_error = false;
    db_connect($db['DB_SERVER'], $db['DB_SERVER_USERNAME'], $db['DB_SERVER_PASSWORD']);
    if ($db_error == false) {
        if (!db_test_create_db_permission($db['DB_DATABASE'])) {
            $error = $db_error;
        }
    } else {
        $error = $db_error;
    }
    if ($db_error != false) {
        $error = "failed";
        echo step1($db_error);
    } else {
        echo '<h1 style="color:green">Congratulations!</h1>
        Connected Successfuly to datbase <strong>
        <a href="http://www.webune.com/forums/how-to-test-mysql-database-connection.html">Continue &gt;&gt; </a></strong>';
    }
        } else {
            $error = "ERROR: please provide a hostanme";
            echo step1($error);
        }
    break;

    default:
    echo step1('Step 1');
    break;
}
?>
<div align="center">
<img src="http://www.webune.com/images/headers/default_logo.jpg">
</div>
<div align="center">
Script Courtesy of
<a href="http://www.webune.com">Webune PHP/Mysql Hosting</a></div>
</body>
</html>

这篇关于安装magento,获取数据库连接错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆