<?php
$host="localhost";
$user="user";
$password="debashree";
$connect=mysqli_connect($host,$user,$password);
if ($connect->connect_error) {
die("connection_aborted".$connect->connect_error);
}
echo "connected succesfully";
这是mysql连接php脚本。它不断显示
的错误警告:mysqli_connect():( HY000 / 1045):拒绝用户&#39;用户&#39; localhost&#39; (使用密码:YES)在第6行的C:\ xampp \ htdocs \ index.php
注意:尝试在第7行的C:\ xampp \ htdocs \ index.php中获取非对象的属性 连接成功
我无法理解请帮帮我?
答案 0 :(得分:1)
您应该尝试进行以下更改:
<?php
try{
$host="localhost";
$user="user";
$password="debashree";
$databaseName = "myDB";
$connect=mysqli_connect($host,$user,$password, $databaseName);
if (**mysqli_connect_errno()**)
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "connected succesfully";
}catch(Exception $e){
echo $e->getMessage();
}
另外,mysqli_connect需要数据库作为第四个参数。
mysqli_connect( “本地主机”, “my_user”, “MY_PASSWORD”, “MY_DB”);