简体   繁体   中英

How to insert data to remote database from local computer?

I am having shared server with cpanel.I have mysql database on server.I want to insert or update data to remote database by running php script on my local computer.Please give me solution. Thanks.

 /* mysql database properties */
    $host = 'mydomain.com'; // or I.P address of domain
    $user = 'database user name'; 
    $pass = 'database password';
    $database = 'database Name';
    $table = 'Table Name';

    /* Database Connection */
    $connection = mysql_connect($host,$user,$pass) or die (mysql_error());
    mysql_select_db($database, $connection) or die(mysql_error());
    $name = 'Amir Khan';
    $age = '27';
    /* Insert query */
    $sql_query = "INSERT INTO $table (name, age) VALUES ('$name', '$age');";
    $result = mysql_query($sql_query,$connection) or die(mysql_error());

    /*update query too same like above*/

    /* you can go mysqli or PDO  for better query structure*/

这是连接到 MySQL 远程数据库并从本地 csv 文件插入的一行查询

mysqlimport --ignore-lines=1 --fields-terminated-by=',' --lines-terminated-by="\n" --local -u <username> -p'<password>' -h <hostname> -P <port> <database>  <tablename>.csv

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