2019-03-15 16:39



I am trying to access a database which is in root@localhost from a website hosted by godaddy.

i created a php file in the project folder and trying to access the local mysql database

here is the code




if (!$db) {
    die("Connection failed: " . mysqli_connect_error());
echo "Connected successfully";


it gives me the error on the browser

Connection failed: Access denied for user 'cancan'@'localhost' (using password: YES)

The website i created is just static html without a back end..

I am pretty new to back end developing , Please help me

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douhui7136 douhui7136 2年前

    So long as Godaddy doesn't block outgoing MySQL connections and your ISP doesn't block incoming MySQL connections, this is technically possible.

    You would need to:

    1. Configure MySQL to listen on your computer's external network interface (i.e. not on a UNIX socket nor on the loopback IP address).
    2. Ensure that the MySQL service is available on the Internet (which will probably mean configuring your Internet router to perform port forwarding for the MySQL port from the Internet to your development machine)
    3. Change the connection string in your PHP so it connects to the hostname or IP address of your computer on the Internet (probably your router's external IP address).

    You'd probably want to ensure you have a static IP address on the Internet so that you don't need to update the PHP every time your IP changes.

    This, however, will be slow (because your MySQL traffic has to go back and forth across the Internet) and risky from a security perspective.

    So don't do it. Get a MySQL service from Godaddy.

    点赞 评论 复制链接分享
  • duandie0921 duandie0921 2年前

    GoDaddy can't access database which is hosted on your computer. For that to be possible your computer must have a Public IP address, It's only that way you can connect website hosted on GoDaddy to your local database and for that you must reference you local computer by their Public IP address and not as localhost within your phone script.

    When you use localhost in script host on GoDaddy It will not reference your computer but the server on which that script is hosted

    点赞 评论 复制链接分享