简体   繁体   English

在mysqli连接中使用IP地址代替“ localhost”作为主机名

[英]Using IP address instead of 'localhost' as hostname in mysqli connection

I am perhaps being a bit overly cautious asking this and apologies if it has been but I want to be as secure as possible. 我可能会有点过分审慎,询问是否已经道歉,但我想尽可能地保持安全。 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? 通过下面的mysqli连接连接到数据库时,使用托管帐户的IP地址而不是本地主机是否同样安全? Would the speed of connection be dramatically affected at all? 连接速度会受到根本影响吗?

$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; } 

The main reason I ask is because at the moment I am exporting my live website database and importing it into my local website testing enviroment (xampp). 我问的主要原因是因为目前我正在导出实时网站数据库并将其导入到本地网站测试环境(xampp)中。 This takes ages and I just thought it may be a better idea to connect directly to the live database. 这花了很长时间,我只是认为直接连接到实时数据库可能是一个更好的主意。

Thanks 谢谢

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? 通过下面的mysqli连接连接到数据库时,使用托管帐户的IP地址而不是本地主机是否同样安全?

No. See 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? 连接速度会受到根本影响吗?

Since you are getting the data from a computer at a remote site instead of locally — yes, it will. 由于您是从远程站点而非本地计算机上获取数据的,所以可以。


local website testing enviroment (xampp). 本地网站测试环境(xampp)。 This takes ages and I just thought it may be a better idea to connect directly to the live database 这花了很长时间,我只是认为直接连接到实时数据库可能是一个更好的主意

Risking your live data by exposing it to your test code is a very bad idea. 通过将实时数据暴露于测试代码中来冒风险,这是一个非常糟糕的主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP gethostbyname返回主机名而不是IP地址 - PHP gethostbyname returns hostname instead of IP address 使用IP地址而不是本地主机时,上传文件不起作用 - Upload file not working when using ip address instead of localhost 在docker中使用localhost而不是db作为mysql主机名 - Using localhost instead of db for the mysql hostname in docker 是否可以在laravel中使用IP地址而不是localhost? - Is it possible to use Ip address instead of localhost in laravel? MySQL 连接使用我的主机名而不是 ipv4 地址,导致无法访问 - MySQL connection using my hostname instead of ipv4 address, leading to no access 如何使用本地IP地址而不是localhost访问数据库mysql服务器 - How can I access my database mysql server using my local ip address instead of using localhost 在URL中使用IP地址而不是localhost时如何解决WAMP页面访问 - How to fix WAMP page access when using IP Address instead of localhost in the URL 为什么使用IP地址而不是localhost时未加载CSS和JS文件 - Why CSS and JS files are not loaded when using IP address instead of localhost 如何在PHP Symfony中连接到IP地址而不是localhost? - How to connect to IP address instead of localhost in php Symfony? 当我使用我的IP地址而不是localhost作为URL时出错 - error when i used my ip address instead of localhost as URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM