Articles Tagged 'Database'

Very short snippet: get the number of posts, Page and Attachment

How many of you know, the table wp_posts is used to store the WordPress post, pages and attachments. The type of the item stored is determined by the field post_type . . With select proposed below, you can "count" individually the various types of elements in memrizzate wp_posts .

Continued ...

Cleanfix WP 0.3.0 beta release

WP Cleanfix is a Plugin for WordPress (also compatible with WordPress MU - will exist as long as this distinction) I wrote to optimize, maintain, clean and fit our Database WordPress.

WP CleanFix

Continued ...

Very short trick: duplicate or clone one or more rows in MySQL

To duplicate the contents of a table full of itself, just use:

1
* FROM MYTABLE INSERT INTO SELECT * FROM MyTable MYTABLE

You can also use the Claus WHERE if necessary:

1
* FROM MYTABLE WHERE a = b INSERT INTO SELECT * FROM MyTable WHERE MYTABLE a = b

If the table has any index or unique key, which would cause an error, you can filter the fields to be duplicated:

1
field1 , field2 , ... ) SELECT field1 , field2 , ... FROM MYTABLE INSERT INTO MYTABLE (field1, field2, ...) SELECT field1, field2, ... FROM MyTable

Even you can duplicate a record and change a value, such as dual field and add 1:

1
field1 , field2 , ... ) SELECT ( field1 + 1 ) , field2 , ... FROM MYTABLE INSERT INTO MYTABLE (field1, field2, ...) SELECT (field1 + 1), field2, ... FROM MyTable

Continued ...

Very short trick: export with PHPMyAdmin given by

When performing an export from phpMyAdmin you can preset the field "File name template" in the "Save As ...", so that automatically adds the current date. Normally this field is preset to __DB__ , which represents the database name. By placing such __DB__-%Y%m%d otteremo the name of our database, followed by the year, month and day currents: miodb-20081010

Continued ...