Monday, January 18, 2010

MySQL and wordpress

If you are like me, and trying to figure out how to merge databases and save yourself time (or buy yourself time if you want to do extra coding but have to get moving NOW), you will benefit from understanding the structure of your WordPress MYSQL database. I have pasted the SQL for the create table command for the table wp-posts in the wp database.


TABLE `wp_posts` (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`post_author` bigint(20) unsigned NOT NULL default '0',
`post_date` datetime NOT NULL default '0000-00-00 00:00:00',
`post_date_gmt` datetime NOT NULL default '0000-00-00 00:00:00',
`post_content` longtext NOT NULL,
`post_title` text NOT NULL,
`post_excerpt` text NOT NULL,
`post_status` varchar(20) NOT NULL default 'publish',
`comment_status` varchar(20) NOT NULL default 'open',
`ping_status` varchar(20) NOT NULL default 'open',
`post_password` varchar(20) NOT NULL default '',
`post_name` varchar(200) NOT NULL default '',
`to_ping` text NOT NULL,
`pinged` text NOT NULL,
`post_modified` datetime NOT NULL default '0000-00-00 00:00:00',
`post_modified_gmt` datetime NOT NULL default '0000-00-00 00:00:00',
`post_content_filtered` text NOT NULL,
`post_parent` bigint(20) unsigned NOT NULL default '0',
`guid` varchar(255) NOT NULL default '',
`menu_order` int(11) NOT NULL default '0',
`post_type` varchar(20) NOT NULL default 'post',
`post_mime_type` varchar(100) NOT NULL default '',
`comment_count` bigint(20) NOT NULL default '0',
PRIMARY KEY (`ID`),
KEY `post_name` (`post_name`),
KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
KEY `post_parent` (`post_parent`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=26 ;


For interacting with other databases or writing programs to 'talk' to your posts, it is important to know the variable types, so you don't add the wrong stuff and to know that none of the variables can be null, but several have a default setting.

If you were pasting data into your table, you wouldn't want to paste the wrong type of data and break your wordpress installation. You can also tell that you really only need to insert data into: post_author, post_date, post_date_gmt, post_content, post_title, and probably post_excerpt. You should be clear of what you are posting by identifying each column that you will be adding data into with the insert into command. INSERT INTO 'wp_posts' ('column1','column2', etc) VALUES('value1,'value2','valueetc')

If you just sayINSERT INTO 'wp_posts' VALUES('value1, 'value2', 'valueetc'), mysql will think you are writing to columns in order, like ID, post_author, etc. This will create all sorts of errors and heartache for you.

No comments:

Post a Comment