php copy table from one database to another

Solutions on MaxInterview for php copy table from one database to another by the best coders in the world

showing results for - "php copy table from one database to another"
Leigh
09 Sep 2020
1// Create a new MySQL database connection
2if (!$con = new mysqli('localhost', $username, $password, $database)) {
3    die('An error occurred while connecting to the MySQL server!<br><br>' . $con->connect_error);
4}
5
6// Create an array of MySQL queries to run
7$sql = array(
8    'DROP TABLE IF EXISTS `backup_db.backup_table`;',
9    'CREATE TABLE `backup_db.backup_table` SELECT * FROM `live_db.live_table`'
10);
11
12// Run the MySQL queries
13if (sizeof($sql) > 0) {
14    foreach ($sql as $query) {
15        if (!$con->query($query)) {
16            die('A MySQL error has occurred!<br><br>' . $con->error);
17        }
18    }
19}
20
21$con->close();
22