donglunzai4288
2019-03-18 20:03
浏览 274
已采纳

php通过mysqli连接mysql数据库

I try to connect to a mysql database via PHPs mysqli.

define('DB_SERVER', '127.0.0.3');
define('DB_USERNAME', '570466');
define('DB_PASSWORD', 'pssst!');
define('DB_NAME', 'db570466');

/* Attempt to connect to MySQL database */
$mysqli = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

And get the following error: Warning: mysqli::mysqli(): (HY000/1045): Access denied for user '570466'@'localhost' (using password: YES) in /.../config.php on line 16

The strange thing is, that Access is denied for my user @localhost, but I don't connect to localhost. According to my hoster (domainFactory), I can also connect to the DB via mysql5.my-domain.tld, but that gives me the same output.

What am I missing?

图片转代码服务由CSDN问答提供 功能建议

我尝试通过PHP mysqli连接到mysql数据库。

 <  code> define('DB_SERVER','127.0.0.3'); 
define('DB_USERNAME','570466'); 
define('DB_PASSWORD','pssst!'); 
define('DB_NAME','db570466'  ); 
 
 / *尝试连接MySQL数据库* / 
 $ mysqli = new mysqli(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_NAME); 
   
 
 

并得到以下错误: 警告:mysqli :: mysqli():( HY000 / 1045):在/.../config中拒绝用户'570466'@'localhost'(使用密码:YES) 第16行的.php

奇怪的是,我的用户 @localhost 拒绝访问,但是我没有连接到localhost 。 根据我的hoster(domainFactory),我也可以通过 mysql5.my-domain.tld 连接到数据库,但这给了我相同的输出。

我错过了什么?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • duanqin9631 2019-03-20 18:17
    最佳回答

    According to the help pages, database usernames for DomainFactory should start with "db":

    Den Usernamen Ihrer Datenbank sehen Sie im Kundenmenü unter "MySQL-Datenbanken". Er hat das Format db12345 bzw. db12345_1 bei weiteren Datenbanken.

    (translated:)

    The username for your database can be found in the customer portal under "MySQL databases". It has the format db12345 or db12345_1 for subsequent databases.

    So you should be able to connect to the database "db570466" using the username db570466 instead of just 570466.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题