简体   繁体   English

php通过mysqli连接mysql数据库

[英]php connect mysql database via mysqli

I try to connect to a mysql database via PHPs mysqli. 我尝试通过PHP mysqli连接到mysql数据库。

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 并得到以下错误: 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. 奇怪的是,我的用户@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. 根据我的托管人(domainFactory),我还可以通过mysql5.my-domain.tld连接到数据库,但这将提供相同的输出。

What am I missing? 我想念什么?

According to the help pages , database usernames for DomainFactory should start with "db": 根据帮助页面 ,DomainFactory的数据库用户名应以“ db”开头:

Den Usernamen Ihrer Datenbank sehen Sie im Kundenmenü unter "MySQL-Datenbanken". 用户名Ihrer Datenbank位于“ MySQL-Datenbanken”。 Er hat das Format db12345 bzw. 格式为db12345bzw。 db12345_1 bei weiteren Datenbanken. db12345_1 beit weiteren Datenbanken。

(translated:) (翻译:)

The username for your database can be found in the customer portal under "MySQL databases". 您可以在客户门户的“ MySQL数据库”下找到数据库的用户名。 It has the format db12345 or db12345_1 for subsequent databases. 对于后续数据库,其格式为db12345或db12345_1。

So you should be able to connect to the database "db570466" using the username db570466 instead of just 570466 . 所以,你应该能够连接到数据库“db570466”使用用户名db570466 ,而不只是570466

You are using 127.0.0.3, but it is rejecting "localhost". 您正在使用127.0.0.3,但它拒绝“ localhost”。 So use "localhost" instead. 因此,请改用“ localhost”。 And be sure the user 570766@localhost has permission. 并确保用户570766 @ localhost具有权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM