gpt4 book ai didi

php - 用户 '' @'localhost' 的访问被拒绝(使用密码 : NO)

转载 作者:行者123 更新时间:2023-11-30 23:54:59 25 4
gpt4 key购买 nike

<分区>

尝试使用以下代码连接到本地主机 sql db(此时不对查询执行任何操作,只想执行查询):

<?php

$host = "localhost";
$port = 3306;
$socket = "";
$user = "root";
$password = "Password1";
$dbname = "CIIP_WIKI";

$con = new mysqli($host, $user, $password, $dbname, $port);

if(!$con)
{
echo ("db connection failed!");
die ('Could not connect to the database server' . mysqli_connect_error());
}

else {
echo ("db connection established.");
echo ("<br/>");
}

$query = sprintf("SELECT first_name FROM actor WHERE actor_id='1'");

$result = mysql_query($query);

$con->close();

?>

我不断收到以下...

Welcome

db connection established.

Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in C:\Program Files (x86)\EasyPHP-12.1\www\Cisco Wiki\index.php on line 31

Warning: mysql_query(): A link to the server could not be established in C:\Program Files (x86)\EasyPHP-12.1\www\Cisco Wiki\index.php on line 31

为什么这不起作用?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com