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

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.

Related

Export MySQL column aliases in phpMyadmin

I am currently moving from one ticketing system to another. The table columns are close but not quite. I can run a query that will change the column name to what I need. However, when I export I am getting the original column name.
Here is the query with alias:
SELECT u.id AS staff_id
FROM users AS u
This gives me what I need. However when I export it, it is showing the original column names. Is there a way to keep the alias when exporting?
Since you're using phpMyAdmin, you can quickly use the "Rename exported databases/tables/columns" feature to rename your table and/or columns when exporting. (I believe this feature was added with version 4.6.0).
On the export page, select the "Custom - display all possible options" radio button, then in the "Output" area look for the "Rename exported databases/tables/columns" checkbox, which opens an additional dialog where you can adjust these names.

MySQL table from phpMyAdmin's tracking reports

Using phpMyAdmin I can track a certain table's transactions (new inserts, deletes, etc), but is it possible to change or export it to a SQL table to be imported into my site using PHP.
While it is not exactly what I was looking for, I found a way to do it for the time being, one of the tables in the phpmyadmin (it's own) database is called pma__tracking, which contains a record of all tables being tracked, one of its columns is the data_sql longtext column which writes each report (ascendingly which is a bit annoying) in the following format
# log date username
data definition statement
Just added it for future references.

Check for changes in database schema and update

At our company we have a business solution which includes CMS, CRM and several other systems.
These are installed in several domains, for each of our clients.
The systems are still in development, so new tables and fields are added to the database.
Each time we want to release a new version to our clients, i have to go through their database and insert the new fields and tables manually.
Is there a way that this could be done automatically(a script maybe that detects the new fields and tables and inserts them?)
We are using php and mysql.
We would like to avoid backing up the clients data, dropping the database tables, running the sql query to insert all the database tables(including the new ones) and then re-inserting the customers data. Is this possible?
Toad for MySQL
DB Extract, Compare-and-Search Utility — Lets you compare two MySQL databases, view the differences, and create the script to update the target.
What you are looking for is
ALTER TABLE 'xyz' ADD 'new_colum' INT(10) DEFAULT '0' NOT NULL;
or if you want to get rid of a colum
ALTER TABLE 'xyz' DROP 'new_colum';
Put all table edits into an update.php file and the either call and delete it once manually or try to select "new_colum" once and update the database when it's not present.
OR what I do: "I have a settingsfield "software version" and use this as a trigger to update my tables.
But since you have to install the new scripts anyways you can just call it manually.

How to select an entire database and display all the information

Is it possible to select all the tables from a database (not knowing their names) and displaying them?
My friend has a mysql server but he doesn't have phpMyAdmin installed and he's begging me to transfer all his php-fusion accounts to his new WordPress blog. He doesn't understand a thing with mysql...
Anyone got an idea?
Use the SHOW and DESCRIBE statements. That's all phpMyAdmin is doing in the code. Your SQL user should have privileges.
List all tables:
SHOW tables;
List table definition:
DESCRIBE table_name;
Check out MySQL for more details.

mysql show table / columns - performance question

I'm working on a basic php/mysql CMS and have a few questions regarding performance.
When viewing a blog page (or other sortable data) from the front-end, I want to allow a simple 'sort' variable to be added to the querystring, allowing posts to be sorted by any column. Obviously I can't accept anything from the querystring, and need to make sure the column exists on the table.
At the moment I'm using
SHOW TABLES;
to get a list of all of the tables in the database, then looping the array of table names and performing
SHOW COLUMNS;
on each.
My worry is that my CMS might take a performance hit here. I thought about using a static array of the table names but need to keep this flexible as I'm implementing a plugin system.
Does anybody have any suggestions on how I can keep this more concise?
Thankyou
If you using mysql 5+ then you'll find database information_schema usefull for your task. In this database you can access information of tables, columns, references by simple SQL queries. For example you can find if there is specific column at the table:
SELECT count(*) from COLUMNS
WHERE
TABLE_SCHEMA='your_database_name' AND
TABLE_NAME='your_table' AND
COLUMN_NAME='your_column';
Here is list of tables with specific column exists:
SELECT TABLE_SCHEMA, TABLE_NAME from COLUMNS WHERE COLUMN_NAME='your_column';
Since you're currently hitting the db twice before you do your actual query, you might want to consider just wrapping the actual query in a try{} block. Then if the query works you've only done one operation instead of 3. And if the query fails, you've still only wasted one query instead of potentially two.
The important caveat (as usual!) is that any user input be cleaned before doing this.
You could query the table up front and store the columns in a cache layer (i.e. memcache or APC). You could then set the expire time on the file to infinite and only delete and re-create the cache file when a plugin has been newly added, updated, etc.
I guess the best bet is to put all that stuff ur getting from Show tables etc in a file already and just include it, instead of running that every time. Or implement some sort of caching if the project is still in development and u think the fields will change.

Categories