[英]Which username/password do I use to connect to mySQL
So, I'm SUPER new to mySQL. 因此,我是MySQL的超级新手。 Having issues connecting to my database with PHP.
使用PHP连接到我的数据库时遇到问题。 Hoping someone can point me in the right direction.
希望有人可以指出正确的方向。
I can login to our Cpanel using my username/password. 我可以使用我的用户名/密码登录到我们的Cpanel。 Using the web gui I was able to create a database.
使用Web gui,我能够创建数据库。
Now when I try to connect to the database (or even just the server for that matter) using PHP I get an error: 现在,当我尝试使用PHP连接到数据库(或什至只是服务器)时,出现一个错误:
Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'username'@'servername' (using password: YES) in /home/ropepart/public_html/techportal/sandbox/mysqltest.php on line 8 Connection failed: Access denied for user 'username'@'servername' (using password: YES)
警告:mysqli :: __ construct():(HY000 / 1045):在第8行的/home/ropepart/public_html/techportal/sandbox/mysqltest.php中,用户'username'@'servername'的访问被拒绝(使用密码:是)连接失败:用户'username'@'servername'的访问被拒绝(使用密码:是)
To me, it seems like this is a username/password error. 对我来说,这似乎是用户名/密码错误。 But I an using the same username/password that I use to login to the web gui.
但是我使用与登录Web GUI相同的用户名/密码。 Why can I successfully login there, but can't login with PHP?
为什么我可以在那里成功登录,但不能使用PHP登录?
Here's my code (taken pretty much directly from W3Schools): 这是我的代码(几乎直接来自W3Schools):
<?php
$servername = "servername";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
(Hopefully it's obvious that I've changed my servername/username/password for the purposes of this post) (希望本文已更改了服务器名/用户名/密码,这很明显)
Check the details correctly, By deafult 正确检查详细信息,默认
host = localhost 主机=本地主机
username = root 用户名=根
password = (No password leave it as empty) 密码=(没有密码,请保留为空)
database = (your database) 数据库=(您的数据库)
<?php
$connection = new mysqli('host','username','password','your_database');
if($connection->connect_error || $connection->error){
echo "error";
}else{
echo "done";
}
?>
you should add database name. 您应该添加数据库名称。
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo"
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
//if you are using xampp you shoul locate this file you get information from this passwords.txt //如果您使用的是xampp,则应找到该文件,并从passwords.txt中获取信息
MySQL database username/password is not necessarily same as cPanel username & password. MySQL数据库的用户名/密码不一定与cPanel用户名和密码相同。
Here is what you should do: 这是您应该做的:
mysqli_connect(serverhostname,username,password,dbname);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.