gpt4 book ai didi

php - 尝试使用php访问远程数据库

转载 作者:行者123 更新时间:2023-11-29 21:38:32 25 4
gpt4 key购买 nike

嗨,我正在尝试使用 PHP 访问远程数据库。远程数据库是MySQL。以下是我遇到的错误的屏幕截图。任何人都可以帮助我。提前致谢。

我检查过以下内容完全没问题:-

  1. 数据库名称
  2. 端口号
  3. IP地址
  4. 用户名和密码

这是数据库连接代码

<?php

class Database {
/*
public $dbhost = "mysql:dbname=a_t;host=localhost:3306";
$dbhost = "mysql:host=10.75.225.171;port=3306;dbname=apt";
public $dbuser = "root";
public $dbpass = "root";
public $dbname = "a_t";
public $connection;
public $selectdb;
public $isConnected;
public $dbh;

*/

public $dbhost = "mysql:dbname=25thcraft;host=52.xx.xx.xxx;port=3306";

public $dbuser = "tribhuvan";
public $dbpass = "123456";
public $dbname = "25thcraft";
public $connection;
public $selectdb;
public $isConnected;
public $dbh;

//$user = 'dbuser';
//$password = 'dbpass';

public function Connection()
{
try
{
$this->dbh = new PDO($this->dbhost, $this->dbuser, $this->dbpass);
// echo "true";
return $this->dbh;
}
catch(Exception $e)
{
$this->isConnected = false;
throw new Exception($e->getMessage());
}
}

public function Disconnect()
{
$this->datab = null;
$this->isConnected = false;
}
}
?>

enter image description here

最佳答案

如果要建立到远程连接的连接,则必须将主机配置为接受这些连接。默认情况下禁用哪些。最好你可以联系房东来调查一下。

关于php - 尝试使用php访问远程数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34723203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com