duanrao3371 2019-03-15 16:39
浏览 153


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

  • 写回答

2条回答 默认 最新

  • douhui7136 2019-03-15 17:01

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 visionmaster启动失败,提示为“机器不满足授权而被禁用”
  • ¥50 用logisim设计16位单时钟周期cpu
  • ¥15 IDEA中圈复杂度如何具体设置
  • ¥50 labview采集不了数据
  • ¥15 请上面代码做什么处理或什么混淆
  • ¥15 英雄联盟自定义房间置顶
  • ¥15 W5500网线插上无反应
  • ¥15 如何用字典的Key,显示在WPF的xaml中
  • ¥15 weautomate读取Excel表格信息然后填写到网页一直报错,如何解决?
  • ¥15 C#如何在Webview2中获取网页验证码