create a table with php and mysql using SHOW CREATE TABLE
Get the solution ↓↓↓Solution:
The following query will create new table, column attributes and indexes will also be copied.
CREATE TABLE new_table_name LIKE old_table_name;
And if you also want the rows copied, then execute following query after executing the above
INSERT INTO new_table_name SELECT * FROM `old_table_name`;
http://www.mysqlfaqs.net/mysql-faqs/Data-Back-Up/How-to-create-duplicate-table-in-MySQL
http://www.tech-recipes.com/rx/1487/copy-an-existing-mysql-table-to-a-new-table/
Answer
Solution:
<?php
$result=mysql_query("SHOW TABLES");
$oldTableName="TABLE1";
$found=false;
while($row=mysql_fetch_array($result))
{
if($row[0]==$oldTableName)
{
$found=true;
break;
}
}
if($found)
{
//TODO Code for table1
}
else
{
//TODO Code for table2
}
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: you must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.