简体   繁体   English

我在wamp服务器上创建了一个名为“ credentials”的数据库,其中包含“ userinfo”表。 我无法通过php连接数据库

[英]I have created a database named 'credentials' having 'userinfo' table in it on wamp server. I am not able to connect the database through php

Error: Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES) in C:\\wamp\\www\\form\\update.php on line 8 错误:警告:mysqli :: mysqli():(HY000 / 1045):在第8行的C:\\ wamp \\ www \\ form \\ update.php中,用户'username'@'localhost'的访问被拒绝(使用密码:是)

PHP code: PHP代码:

<?php

$servername = 'localhost';
$username = 'username';
$password = 'password';
$dbName = 'credentials';

$link = new mysqli($servername, $username, $password, $dbName);
if (!$link) {

    die("Connection Failed: " . mysqli_connect_error());
}

$connect = "INSERT INTO userinfo (username, password) VALUES ('$username', '$password')";
if (mysqli_query($link, $connect)) {

    echo "New record created successfully";
}else {

    echo "Error: " . $connect . "<br>" . mysql_error($link);
}
mysqli_close($link);
?>

Need to grant permissions to the user@host in mysql. 需要向mysql中的user @ host授予权限。 The grant command looks like grant命令看起来像

grant all privileges on YOURDB.* to 'YOURUSER'@'localhost' identified by 'YOURPASSWORD';

The value of variables: 变量的值:

$username = 'username';
$password = 'password';

Must be the REAL login information of your database server, something like 'root' or another user, and the password defined during the server setup. 必须是数据库服务器的REAL登录信息,例如“ root”或其他用户,以及服务器设置期间定义的密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法连接到数据库? - Why am I not able to connect to my database? 使用PHP添加到WAMP服务器中创建的数据库? - Using PHP to add to a database created in WAMP server? 我正在尝试用PHP 5连接数据库,它与Test命名数据库连接良好,但没有与其他命名数据库连接 - i am trying to connect the database in PHP 5, it connects fine with Test named DB, but it doesn't with different named DB 无法连接到PHP中的数据库(使用WAMP服务器) - Unable to connect to database in php (using wamp server) 无法从 php 脚本插入数据库我正在使用 WAMP - Cannot insert into database from php script I am using WAMP 如何在通过xampp服务器导出的filezilla中使用上载的.sql数据库。 - How can I use uploaded .sql database in filezilla which I have been exported through xampp server. 我是PHP新手,无法将表单与数据库连接。 RouteCollection.php行179中的NotFoundHttpException: - I am new at PHP , I am not able to connect my form with database . NotFoundHttpException in RouteCollection.php line 179: 我无法连接服务器 - I am not able to connect the server 无法连接到数据库。 难道我做错了什么? - Not able to connect to database. Am I doing something wrong? 您好,我遇到了通过数据库连接网站链接的问题, - Hello , I am having a Issue with Website Links connectivity through Database,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM