php - How can I connect to a database on an external ip? -


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:

  1. create mysql user in remote server.

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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -