Is there a way to implement:
CREATE TABLE sample LIKE master;
using either Codeigniter active record or dbforge?
The reason being is that this is being executed from an administration panel; the admin is given a form and the new table name is captured from a POST.
You can try this
$tablename = $_POST['tblname'];
$mastertable = $_POST['mastertable']
$this->db->query("CREATE TABLE $tablename LIKE $mastertable");
To copy data
$query = $this->db->get($mastertable);
foreach ($query->result() as $row) {
$this->db->insert($tablename,$row);
}
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.