【问题标题】:Can't connect to database on my website created by using wamp无法连接到我使用 wamp 创建的网站上的数据库
【发布时间】:2017-02-26 15:14:56
【问题描述】:

我安装了 wamp,让它运行,登录 http://localhost:8080/phpmyadmin/ 并创建了一个名为:“automobile”的数据库。我建立了自己的网站,它正在运行。但是当我想使用我的数据库时,我不能。 我有这个错误:

警告:mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp\www\connect.php on line 8

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

<?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;


?>

【问题讨论】:

  • 尝试使用 127.0.0.1 而不是 localhost
  • 我试过了。不工作。

标签: mysql database wamp


【解决方案1】:

您的数据库有密码?如果您没有为数据库设置通行证,您将无法连接到数据库。

如果您使用 localhost 进行开发,我认为您不需要,现在不需要。您可以在不输入密码变量的情况下进行连接。或者你可以去你的数据库管理器,比如 phpMyAdmin 或 mysql 工作台并设置你的密码。

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

【讨论】:

  • 没有。如何设置数据库通行证?
  • 我想可能是因为我改了3307的端口,他默认使用的是3306端口。但是在这种情况下,我不知道在这个端口上输入什么而不是默认的。
猜你喜欢
  • 1970-01-01
  • 2016-01-15
  • 2014-12-06
  • 2016-07-23
  • 2018-12-20
  • 2015-12-10
  • 2013-06-27
  • 2020-08-02
  • 1970-01-01
相关资源
最近更新 更多