简体   繁体   中英

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? 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). 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?

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM