簡體   English   中英

使用Hostgator連接到MySql數據庫

[英]Connect to MySql Database with Hostgator

我最近從Hostgator購買了一個托管計划,並且使用Cyber​​Duck將一些PHP文件放到了站點上。 他們顯然已上載,因為當我訪問我的域時出現錯誤: 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 ,因此除了通過域進行連接之外,所有設置都已正確設置。

許多hostgator帳戶使您的php和Web服務器與MySQL服務器在同一台計算機上運行。 而且,作為hostgator客戶,您極不可能使用MySQL root帳戶。 它可以讓您查看其他客戶的數據。

Hostgator在每台計算機上都有很多客戶,可以共享它。 (可能太多,但這又是一個問題。)

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM