[英]Unable to connect to database in php (using wamp server)
I have just started learning php and mysql. 我刚刚开始学习php和mysql。 I am using wamp server and I have created a database in phpmyadmin.
我正在使用wamp服务器,并且已经在phpmyadmin中创建了一个数据库。 I have also created a table (user) in this database and added some records in it.
我还在此数据库中创建了一个表(用户),并在其中添加了一些记录。
Now I am trying to connect to this database in my index.php file (which is in www folder). 现在,我尝试在我的index.php文件(位于www文件夹中)中连接到此数据库。
I have few questions here, what is the default username and password of my database that I can use to connect? 我在这里有几个问题,可用于连接的数据库的默认用户名和密码是什么? Where as I am using following statement to connect to database.
我在哪里使用以下语句连接数据库。
$hostname = "localhost";
$username = "root";
$password = "password";
$dbname = "logindb";
$conn = new mysqli($hostname, $username, $password, $dbname);
It is showing me following error when I run it in the browser. 在浏览器中运行它时,它显示以下错误。
Note that I also have following code after the connection 请注意,连接后我也有以下代码
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$myquery = "select * from user";
if (mysqli_query($conn, $myquery)) {
echo "Records retrieved.";
} else {
echo "Error : " . mysqli_error($conn);
}
You have 你有
$username
on the one hand, but then use 一方面,然后使用
$root
when making the actual connection. 进行实际连接时。
$hostname = "localhost";
$username = "root";
$password = ""; default password is null
$dbname = "logindb";
$conn = new mysqli($hostname, $username, $password, $dbname) or die ("Could Not Connect To MySql");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.