简体   繁体   中英

How insert in table from another database MYSQL

I have a table in a hosting I want to communicate with it remotely through my localhost, but I can't reference that I want the table from that database how do I do that?

*im using php *

<?php

// Create connection

$conn = mysqli_connect('localhost', 'root', '','contador');
$conn2 = mysqli_connect('hostingIP', 'userIp', 'userPass');
$tableName='contador';
$dbname2='dbHosting';
$result = mysqli_query($conn2,$dbname2);

$sql = "INSERT INTO tab2 (Data,Acessos) VALUES ( now(),(SELECT COUNT(*) FROM $result.$tableName WHERE DATE(Data)= CURRENT_DATE() - INTERVAL 0 DAY))";

?>

  1. Make an export script in localhost.
  2. Trigger it regularly via cron jobs.
  3. Include FTP credentials to upload it to your server.
  4. Make an import script in your server.
  5. Trigger it regularly via cron jobs.

Thank me later:)

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