douwei1128 2018-05-17 11:07
浏览 151
已采纳

无法使用php连接到服务器

<?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";

This is the mysql connection php script. It is constantly showing the error of

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES) in C:\xampp\htdocs\index.php on line 6

Notice: Trying to get property of non-object in C:\xampp\htdocs\index.php on line 7 connected successfully

I cannot understand please help me?

  • 写回答

1条回答 默认 最新

  • dpnzf48660 2018-05-17 11:27
    关注

    You should try the following changes made :

    <?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();
    }
    

    Also, mysqli_connect requires database as fourth parameter.

    mysqli_connect("localhost","my_user","my_password","my_db");

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!