i connect database external ip of pc on server, 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 that? , if so, how can it? help;)
p.s: sorry bad english
it easy connect remote mysql server using php, have is:
create mysql user in remote server.
give full privilege user:
- firewall of server must set-up enable incomming connections on port 3306
- you must have user in mysql allowed connect
%
(any host) (see manual details)
connect server using php code (sample given below)
$link = mysql_connect('your_my_sql_servername or ip address', 'new_user_which_u_created', 'password'); if (!$link) { die('could not connect: ' . mysql_error()); } echo 'connected successfully'; mysql_select_db('sandsbtob',$link) or die ("could not open db".mysql_error()); // connect localhost @ port 3306
Comments
Post a Comment