Migrating data from ASP to WordPress
August 5th, 2009 | Tutorials
My personal site ArleyM.com has been an ASP site for about six years now, but the time has finally come to port over to WordPress and PHP. A lot of the heavy lifting was done over a year ago when I experimented with using Blogger as an RSS powering blog engine, but there was still some content fueled by a Microsoft Access Database.
In early 2004 I started a database of my Top5 high rotation songs of the week. This was a very simple database table with eight fields. It’s been very rewarding to see this progress kept, so naturally I want to bring it into the new site. On the former version of the site ASP calls the database, and repeats each row of data in a table. I could just copy and paste the HTML tables after they’ve been rendered, but where’s the fun in that? I’d prefer to have each table fall into my blog on the appropriate date for the last five years.
WordPress naturally doesn’t import .mdb files natively, so I knew there would be some wrestling with data! Under Tools > Import WordPress has several proprietary formats it can import, as well as the ubiquitous RSS feed. I decided to convert my database into RSS.
At first I thought it might be a simple matter of exporting the XML (which RSS is a form of), but this was going to require some ugly code work to fit the RSS 2.0 format. In the end, I modified the old recordset page to render the RSS for me!
The old recordset page would call to the database, then populate a table with the songs like so:
This was done with code like:
So it’s just a simple matter of changing up the body content! Obviously I don’t want to do my site layout in Tables again, opting for CSS styling on a list.
As already stated, ASP gathers the records in a Repeat Region. RSS likes content repeated with the <item> tag. So in the end my new ASP record code looked like:
<title>Top5 Tracks for the week of <%=(t5.Fields.Item(“date”).Value)%></title>
<% IF TextShow <>”" THEN%>
<li>Guilty Pleasure: <%=(t5.Fields.Item(“guilty_pleasure”).Value)%>
Now when this renders I can view the source and I’ll have all of my data nicely listed within <Item> Tags! (Note: the entire <content:encoded>tag must be on one line, it wouldn’t fit very nicely here). I went into the rendered HTML, removed the head and footer HTML leaving just the Items.
Next I created an XML file to be my importable RSS. I added the header and footer to the file:
<?xml version=”1.0″ encoding=”UTF-8″?>
<title>Top5 High Rotation Tracks </title>
<description>High rotation tracks of the week</description>
items will paste here…
Then it was a simple matter of pasting in the rows of <Item> after the RSS description, and uploading into WordPress.
The only snag I hit was when all of the dates were coming off as December 31, 1969. I quickly realized that the Date column in my database was actually a text field with entries in the format of “08.0-5.09″ (mm.dd.yy), which looked cool, but meant nothing to the database. A simple find and replace on the period and editing the field to be short-date resolved this issue nicely.