php - 在 mysqli 连接中使用 IP 地址而不是 'localhost' 作为主机名

标签 php mysql

我可能有点过于谨慎地问这个问题,如果有的话,我深表歉意,但我希望尽可能安全。 当我通过下面的 mysqli 连接连接到数据库时,使用我的托管帐户 IP 地址而不是 localhost 是否同样安全?连接速度是否会受到显着影响?

$hostname = "localhost";
$database = "wwwcapco_crm";
$username = "wwwcapco_user";
$password = "cKUsaf#&^0";

$connect = new MySQLi($hostname, $username, $password, $database);

if ($connect->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli- >connect_errno . ") " . $mysqli->connect_error; } 

我问的主要原因是因为目前我正在导出我的实时网站数据库并将其导入到我的本地网站测试环境 (xampp) 中。这需要很长时间,我只是认为直接连接到实时数据库可能是一个更好的主意。

谢谢

最佳答案

Is it just as secure to use my hosting accounts IP address instead of localhost when I connect to the database via my mysqli connection below?

没有。参见 the documentation :

All other information is transferred as text, and can be read by anyone who is able to watch the connection. If the connection between the client and the server goes through an untrusted network


Would the speed of connection be dramatically affected at all?

由于您是从远程计算机而不是本地计算机获取数据 — 是的,它会。


local website testing enviroment (xampp). This takes ages and I just thought it may be a better idea to connect directly to the live database

将您的实时数据暴露给您的测试代码是一个非常糟糕的主意。

关于php - 在 mysqli 连接中使用 IP 地址而不是 'localhost' 作为主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18246745/

相关文章:

php - SELECT 语句在 mariadb 10.0 中不起作用,但在 mariadb 5.5 中起作用

javascript - 如何使用 XMLHTTP 将变量从 JavaScript 传递到 PHP 页面

php - Laravel groupBy 列并根据数量列添加总计

mysql - SQL:存在的地方 -> 比较两个表并检查它们是否具有相同的行数

PHP SQL 和类

php - 无法增加 MAMP php 内存限制

php - 将获取的数据转换并显示为 Bamini 格式

php - 允许使用 mysql 和 php 每隔几个小时访问一次游戏而无需长代码?

php - 从php中的日志文件中删除存储在数组中的内容

mysql - 根据日期插入和更新表行