Getting SQL for already populated tables? PHP My Admin - php

Using MySQL I can run the query:
SHOW CREATE TABLE employee;
And it will return the create table statement for the specified table. This is useful if you have a table already created, and want to create the same table on another database.
Is it possible to get the insert statement for an already existing set of rows, so that if a blank db with the tables created is set up, the sql can be pasted into the query box & all the tables will be populated exactly the same as the original?
Thanks
Example of data populated in the table, retrieving the sql for this.

Check the following link for exporting DB from phpmyadmin
https://mediatemple.net/community/products/dv/204403864/export-and-import-mysql-databases

Related

How to update SQL Query when a new column is added

I was wondering if anyone could help answer this question. I currently have an SQL Query that's being displayed into a table using PHP. I use a separate PHP file to upload data to mySQL table and when I update my table with a new column I have to rerun the SQL Query to get it to update into the PHP table. I was wondering if there was a way using PHP to automatically run that SQL Query when there has been an update to the table.
You can use AJAX and it to run in every second or you can use
meta tag : refresh
this will refresh page with php table

Copy fields from one database to another in MySQL

I have already known that here is question like mine:
PHP/MySQL: Copy Table and Data from one Database to another
But, that question was asked about 4 years ago, so I would like to repeat it today.
INSERT INTO `wp_estate`.`wp_posts`(post_title)
SELECT `s_description` FROM `u519633785_armar`.`oc_t_item_description`
WHERE `fk_i_item_id` > 4;
How I can "see" two databases at the same time
You first have to create a table into database you want to copy the data.
To get the complete CREATE statement of table. Run Following query in your DB:
show create table table_name;
This will return you the complete create query of table.
After creating a table to your new database, you can copy all data from your old table to table of your new DB.
Query to copy data:
insert into newDB.your_table select * from oldDB.your_table;
Updated insert query:
INSERT INTO `wp_estate`.`wp_posts`(post_title)
SELECT `s_description` FROM `u519633785_armar`.`oc_t_item_description`
WHERE `fk_i_item_id` > 4;

Is there a way to copy a table structure to all tables in MySQL database at once?

phpmyadmin allows you to create a new table from a current table by copying its strucutre/strucute+data/data only...etc through a window similar to this...
However is it possible to copy the structure of a table to multiple tables in your database at once ?
one option would be to export the structure of the table. Then copy the sql generated by phpadmin. You could create a php script that iterates over the table names and runs the same alter/create query but replaces the table name.
You can do this using the show TABLES; query in mysql to get the tables then run alter $row[0] ... or create $row[0] ... queries from the export to do the work for you. just replace the table name with the varable name you have set in your loop.

What does Add DROP SYNTAX in X-Cloner of Wordpress mean?

What does "Add DROP SYNTAX" in the XCloner plugin mean?
I checked the manual and it says something I don't understand.
Add MySQL Drop:
Tick this checkbox if you want XCloner to add the DROP TABLE IF
EXISTS statement to your generated SQL. This option is only for
advanced users.
How important is this to check? and will I lose anything if I ignore it? Please explain in both short and long answers.
Thank you.
If you enable this option, the resulting exported SQL will contain DROP TABLE IF EXIST statements. This means that when you try and import said SQL into another database, it will DROP any existing tables that have the same names as the tables contained in the SQL. If I export the tables users, items and news from Database A and I attempt to import them into Database B, any tables with those names will be dropped before those three tables are imported. So, if I already have a table called users in Database B, it will be dropped before the "new" users table is imported. Could be disastrous if you have another app connected to Database B that also uses its own table called users.

Duplicate mysql table "structure" using PHP only

I have table called "users" and I want to make an exact copy as "users_2" as regard the structure only not the content.
I wanna do this using PHP only as I don't have an access to phpMyadmin or mysql console.
Do you have an idea how to do that ?
After connecting to your database appropriately in php (mysql_connect):
mysql_query("create TABLE tablename like SRCTABLE");
You can use the SQL SHOW CREATE TABLE users command, its result is a CREATE TABLE statement in which you can just replace users with users_2 and execute.

Categories