I would like to connect to a database with an external ip of the pc on which the server, for example:
<? $db_host = "xxx.xxx.xxx.xxx" //external ip
$db_user = "user"; $db_password = "password"; $db_database = "database";
$conn = "mysql:host=$db_host;dbname=$db_database;charset=utf8mb4"; try {$db = new PDO($conn , "$db_user", "$db_password");}catch(PDOException $e) {echo 'Error: '.$e->getMessage();}?>
So, can you do that? And if so, how can I do it? Thanks everyone for help;)
P.s: Sorry for my bad English
First Check Your Public IP Address [ Public Ip Means External Ip Address
] From Here : https://www.whatismyip.com/
And Now Check Your System Ip Address ( Internal Ip Address using ipconfig in cmd
)
Both Are Differect So You Need To Used Public Ip Address
Which One You Get From https://www.whatismyip.com
Now, you have to Give Access permission to Database for Specific iP Address, By Default Mysql is not allowing to Access it SO You Need To Fire This Command for .
Like This :
SQL> GRANT ALL PRIVILEGES ON database.* TO 'user'@'your_database_pc_public_ip' IDENTIFIED BY 'newpassword';
Example::
SQL> GRANT ALL PRIVILEGES ON database.* TO 'any_name'@'public_ip' IDENTIFIED BY 'any_password';
Then Its Work Fine For You :)