使用Hostgator连接到MySql数据库

时间:2017-06-22 19:36:16

标签: php mysql web-services

我最近从Hostgator购买了一个托管计划,我有几个PHP文件,我使用Cyber​​Duck放在网站上。它们显然已上传,因为当我访问我的域时,我收到错误:Connection failed: SQLSTATE[28000] [1045] Access denied for user 'root'@'gator4066.hostgator.com' (using password: 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());
  }
?>

我不确定是否需要使用其他username/password/databaseName

我只想提一下,这一切都适用于localhost,所以除了通过域连接之外,所有内容都已正确设置。)

1 个答案:

答案 0 :(得分:0)

许多hostgator帐户让您的php和Web服务器与MySQL服务器在同一台机器上运行。而且,作为hostgator客户,您极不可能使用MySQL root帐户;它可以让你看到其他客户&#39;数据

Hostgator在每台机器上拥有大量客户,并共享它。 (可能太多,但那是另一天的问题。)

因此,您的配置可能是这样的:

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