这是用于连接到 phpMyAdmin 数据库的 connection.php 文件
<?php
require_once 'config.php';
class DB_Connection {
private $connect;
function __construct() {
$this->connect = mysqli_connect(hostname, user, password, db_name)
or die("Could not connect to db");
}
public function getConnection()
{
return $this->connect;
}
}
?>
但是当我尝试使用 Postman 发帖时,我似乎遇到了这个错误
<br />
<b>Warning</b>: mysqli_connect(): (HY000/1130): Host '192.168.98.178' is not allowed to connect to this MariaDB server in
<b>/Applications/XAMPP/xamppfiles/htdocs/connection.php</b> on line
<b>8</b>
<br />
Could not connect to db
最佳答案
了解您的设置是这里的关键。您正在使用 XAMPP 的 MySQL 服务器,对吗?我认为你是基于你之前的问题。您要为主机名、用户、密码和 db_name 传递什么?
XAMPP 的 Mysql 服务器默认有一个 root 用户和一个空密码。因此,让 user = 'root' 和 password = '' 应该可以让你进入。这对生产不利,但它会帮助你同时进行设置。
除此之外,学习 MySQL 以及如何管理它是个好主意。 http://www.mysqltutorial.org/
关于Postman 中的 Php 连接文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42164206/