Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Hostgator连接到MySql数据库_Php_Mysql_Web Services - Fatal编程技术网

Php 使用Hostgator连接到MySql数据库

Php 使用Hostgator连接到MySql数据库,php,mysql,web-services,Php,Mysql,Web Services,我最近从Hostgator买了一个托管计划,我有一些PHP文件,我用CyberDuck放在网站上。它们显然是被上传的,因为当我访问我的域时,我得到了一个错误:连接失败:用户'root'@'gator4066.hostgator.com'的SQLSTATE[28000][1045]访问被拒绝(使用密码:YES)。我需要连接到我的MySQL数据库,但我不确定如何连接。这就是我的database.php文件的外观: <?php $server = 'theServerIPThatHostGa

我最近从Hostgator买了一个托管计划,我有一些PHP文件,我用CyberDuck放在网站上。它们显然是被上传的,因为当我访问我的域时,我得到了一个错误:
连接失败:用户'root'@'gator4066.hostgator.com'的SQLSTATE[28000][1045]访问被拒绝(使用密码:YES)
。我需要连接到我的MySQL数据库,但我不确定如何连接。这就是我的
database.php
文件的外观:

<?php
  $server = 'theServerIPThatHostGatorSentMeInEmail';
  $username = 'root'; // for the database on my PC
  $password = 'myPassword'; // for the database on my PC
  $database = 'auth'; // the name of the database on my PC

  try {
    $conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
  } catch(PDOException $e) {
    die("Connection failed: " . $e->getMessage());
  }
?>

我不确定是否需要使用其他
用户名/密码/数据库名


我只想提一下,这一切都与
localhost
一起工作,因此除了通过域连接之外,其他一切都已正确设置)。

许多hostgator帐户的php和web服务器与MySQL服务器运行在同一台机器上。而且,作为hostgator客户,您使用MySQL根帐户的可能性极低;它将允许您查看其他客户的数据

Hostgator在每台机器上都有很多客户,他们共享这台机器。(可能太多了,但这是另一天的问题。)

因此,您的配置可能如下所示:

 $server = 'localhost';
 $username = 'SOMETHING-SET-UP-IN-YOUR-CONTROL-PANEL'; 
 $password = 'SOMETHING-SET-UP-IN-YOUR-CONTROL-PANEL'; 
 $database = 'yourCustomerName-SOMETHING';

如果数据库和脚本存在于同一台服务器上,请尝试使用本地主机而不是任何严格的IP。另外,请避免使用root用户进行常规数据库访问,而是为web脚本创建另一个。为什么您使用“TheServeripthatHostGatatorSentmineMail”,但将“我的电脑上的数据库”的用户、密码和数据库名称设置为“/”。这是一个简单的错误。。。应该很容易修复。改为使用hostgator数据库的用户名、密码和数据库名。是的,这就是它,但它是服务器IP,而不是locahost。谢谢