When I try to copy database table from one db to another via phpmyadmin copy table to(database.table) operation function everything works fine, but when I do with the below code it works but some value in database table is turned to be null. So can I know how to make exact copy of the database table from one database to another is there is any other way to do so and what is error in the below code which make some tables null.
Note: Only the database table not whole database.
Here is the code
<?php
if (!$con = new mysqli('localhost', 'username', 'password', 'db_movies2'))
{
die('An error occurred while connecting to the MySQL server!<br><br>'.
$con->connect_error);
}
$sql = array('DROP TABLE IF EXISTS ba_content;',
'CREATE TABLE ba_content SELECT * FROM db_movies1.ba_content');
if (sizeof($sql) > 0)
{
foreach ($sql as $query)
{
if (!$con->query($query))
{
die('A MySQL error has occurred!<br><br>' . $con->error);
}
}
}
$con->close();
?>
Here is example of database in which changes that occur automatically when database table is copied via the above PHP code it occurs in most of the tables.
- `content_name` varchar(255) DEFAULT NULL,
- `type` varchar(25) DEFAULT NULL,
+ `content_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
+ `type` varchar(25) CHARACTER SET utf8 DEFAULT NULL,