简体   繁体   English

如何正确连接到mysql数据库?

[英]How do I properly connect to a mysql database?

Here is my code: 这是我的代码:

<?php
    require_once('config.php');
    $link = mysqli_connect($db_host, $db_user, $db_pass, $db_name) or die ('Your DB connection is misconfigured. Enter the correct values and try again.');
?>

I have stored my host, username, password and database name in the separate file config.php. 我已经将主机,用户名,密码和数据库名称存储在单独的文件config.php中。 I know that the information is correct because I can connect to my database via putty, but I keep getting the error: 我知道该信息是正确的,因为我可以通过腻子连接到数据库,但是我不断收到错误消息:

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'blank'@'T9AF3.WPA.blank.Ca' (using password: YES) in C:\\xampp\\htdocs\\temp2\\index.php on line 3 Your DB connection is misconfigured. 警告:mysqli_connect():(HY000 / 1045):在网上C:\\ xampp \\ htdocs \\ temp2 \\ index.php中,用户'blank'@'T9AF3.WPA.blank.Ca'的访问被拒绝(使用密码:是) 3您的数据库连接配置错误。 Enter the correct values and try again. 输入正确的值,然后重试。

Note: 'blank' is there to protect my identity and is not a typing error. 注意:“空白”是为了保护我的身份,不是输入错误。

Edit: I only used putty to test that my login information was correct. 编辑:我只用腻子来测试我的登录信息是正确的。 Putty has very little to do with my actual question. 腻子与我的实际问题关系不大。

Edit2: 编辑2:

<?php
    $db_host = 'host';
    $db_user = 'user';                  
    $db_pass = 'pass';                  
    $db_name = 'dbname';
?>

These are filers. 这些是申报者。

if you can login from putty, by that i think you mean localhost, and you can't from php file, which is i think trying to connect remotely, the problem most probably lies on your user not defined for your servers ip. 如果您可以从腻子登录,那么我认为您的意思是本地主机,而您无法从php文件登录,这是我认为尝试远程连接的问题,最有可能是您的用户未为服务器ip定义的。 your server, which you are trying to connect from is 'T9AF3.WPA.blank.Ca' in mysql a username has a password and a location and mysql uses both to authenticate the user. 您尝试从中连接的服务器是mysql中的“ T9AF3.WPA.blank.Ca”,用户名具有密码和位置,并且mysql都使用这两者来对用户进行身份验证。 you can have permission to connect locally but not remotely ie from another server. 您可以拥有本地连接权限,但不能远程连接(即从另一台服务器连接)。 check with your system admin to make sure you have proper access defined from 'T9AF3.WPA.blank.Ca'. 请与系统管理员联系,以确保您具有从“ T9AF3.WPA.blank.Ca”定义的正确访问权限。

Or you have not specified an IP Address for the server to listen to. 或者您没有指定服务器要监听的IP地址。 It may only be listening on localhost of your server, instead of allowing remote connections. 它可能仅在服务器的本地主机上侦听,而不允许远程连接。 Check your mysql configuration and which IP address it is listening on. 检查您的mysql配置以及它正在监听的IP地址。

您的mysql用户必须对正在使用的数据库具有适当的权限

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

相关问题 如何正确连接到 MySQL 数据库? - How to connect properly to MySQL database? 如何将本地数据库连接到服务器MYSQL数据库 - How do I Connect to the Local database to the Server MYSQL database 使用 PHP 和 MySQL,如何正确地将智能引号写入数据库? - With PHP and MySQL, how do I properly write smart quotes to the database? 如何连接到heroku上的外部mysql数据库? - How do I connect to external mysql database on heroku? 如何在PALM webOS中连接到外部数据库(例如MySQL) - How do I connect to an external database such as MySQL in PALM webOS 如何将Dreamweaver连接到1and1上的MySQL数据库? - How do I connect Dreamweaver to a MySQL database on 1and1? 如何从 Android 应用程序连接 MySQL 数据库? - How do I connect with MySQL database from Android application? 如何使用PHP连接到在线MySQL数据库? - How do I connect to an online MySQL database using PHP? 在PrestaShop中创建新模块时,如何在不使用mysql_connect的情况下连接到数据库 - How do I connect to the database with out using the mysql_connect when creating the new module in PrestaShop 如何在mySQL数据库中正确存储textarea的换行符? - How do I store line-breaks from textarea properly in mySQL database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM