无法连接到使用wamp创建的网站上的数据库

时间:2017-02-26 15:14:56

标签: mysql database wamp

我安装了wamp,让它运行,登录http://localhost:8080/phpmyadmin/并创建了一个名为:" automobile"的数据库。我创建了自己的网站并且正在工作。但是当我想使用我的数据库时,我无法做到。 我有这个错误:

警告:mysqli_connect():( HY000 / 1045):拒绝访问用户' root' @' localhost' (使用密码:是)在第8行的C:\ wamp \ www \ connect.php

这是我的文件,应该将我连接到我的数据库。

<?php
    $host = "localhost";
    $user = "root";
    $passw = "root";
    $db = "automobile";

    $link = mysqli_connect($host, $user, $passw, $db);

    // Verificarea conexiunii
    if (mysqli_connect_errno()) {
        echo "Problema la conectare la baza de date " . mysqli_connect_error();
    }
    else {
        //echo "Conectare cu succes la baza de date <br>";
    }
?>

这是来自WAMP的config.inc文件:

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * phpMyAdmin sample configuration, you can use it as base for
 * manual configuration. For easier setup you can use setup/
 *
 * All directives are explained in documentation in the doc/ folder
 * or at <http://docs.phpmyadmin.net/>.
 *
 * @package PhpMyAdmin
 */

/*
 * This is needed for cookie based authentication to encrypt password in
 * cookie
 */
$cfg['blowfish_secret'] = 'a8b7c6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

/*
 * Servers configuration
 */
$i = 0;

/*
 * First server
 */
$i++;
/* Authentication type */
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
//$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'root';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Servers'][$i]['port'] = 3307;



/*
 * phpMyAdmin configuration storage settings.
 */

// No warning on  pmadb tables
$cfg['PmaNoRelation_DisableWarning'] = true;


?>

1 个答案:

答案 0 :(得分:0)

您的数据库有密码吗?如果没有为数据库设置传递,则不会连接数据库。

如果您使用localhost开发,我认为您不需要,现在不需要。您可以直接连接而不输入密码变量。或者你可以去找你的db管理器,比如phpMyAdmin或mysql workbench,并为你设置密码。

可能是空白密码,例如$passw = "";