Importing Data into Your MySQL Database
Website Automation with PHP and MySQL, Part 3
Low End Mac Reader Specials
Memory To Go Special: New 2008 iMac 2GB $42 / iMac Intel Core2 DUO & MacBook Pro 2GB $36 - 1GB $20. MacPro 8 Core Memory 4GB kit $154 / 2GB kit $94 -- Free shipping available.
Download Typestyler, still the Ultimate Styling Tool for Internet, Print and Video Graphics. Works great in Classic with a Native OS X Version on the way. Free Tryout: www.typestyler.com
LA Computer Company: Specials on AppleCare, iMac's, Apple Batteries and Apple A/C Adapters. Also Great prices on Used Apple Computers. Call 1-800-941-7654 Click Here.
OWC: Upgrade to a Larger Hard Drive, Add Additional Drives SATA for Mac Pro and G5s, up to 1.0TB in each Bay. 500GB from $90!
Mac users can finally play Party Poker for Mac. Not only that, they can also learn how to play PokerStars for Mac.
Laptop Hardware Provided by TechRestore - Overnight Mac & iPod Repairs.
Compare products like desktop computers, laptops, and LCD TVs side by side! All the information and reviews to make the best purchasing decision for a new cell phone GPS products or MP3 players. The Ciao network makes searching products easy for you.
New MacPro Memory 800Mhz With Apple Spec Heat Sink 2GB $88 / 4GB $138 / 8GB $274 - Click to Maximize your Macs...
Dan Knight - 2002.04.25
Last time we created our database with four fields: id, link, model, and text. Now we need to fill the database.
Again, there are two ways to do things. The hard way is to use Telnet and manually enter all of your data. The easy way, assuming you have the data in a file, is to import your information.
Filling the Mac of the Day Database
Call me lazy, but I simply don't want to spend a lot of time rekeying this information or doing the cut-and-paste thing. Three fields time nearly 100 Macs would take a long time.
Besides, I already had everything in HTML format. Here's the line for the Mac Plus as an example:
- <A HREF="/compact/macintosh-plus.html">Mac Plus</A> (1/86-10/90). First Mac with SCSI, memory expansion. Longest model life - over 4 years.
I wanted to break this down to three fields: link, model, and text, as follows:
- link: compact/plus.shtml
- model: Mac Plus
- text: (1/86-10/90). First Mac with SCSI, memory expansion. Longest model life - over 4 years.
I'd add the id field manually, since it didn't exist in my HTML file.
The first step was to take the raw HTML from my file and copy it into TextSoap, a powerful program for cleaning up text with manual line breaks, extra spaces, and other problems. Running the scrub command reconnected the HTML lines that Home Page had nicely broken into pieces.
Then we copied that code to BBEdit Lite, where our next step was to eliminate the extra space between lines of code. Search for \r\r (two returns) and replace with \r. Then save the file to the desktop.
As Brian < http://brkn.net/> explained to me, before you go any further you need to "escape" things like quote marks. So we did a global search for the quote mark and replaced it with \" - the backslash is used to indicate that the next character is literal instead of punctuation. We did the same with parentheses.
Our Mac Plus description now looked like this:
- <A HREF="/compact/macintosh-plus.html">Mac Plus</A> \(1/86-10/90\). First Mac with SCSI, memory expansion. Longest model life - over 4 years.
We also stripped out the unnecessary HTML code such as <A HREF="/ and "> and </A> . Because MySQL likes to work with comma delimited files, we replaced "> with ", " and also replaced </A> with ", ". Now it looked like this:
- compact/plus.shtml", "Mac Plus", "\(1/86-10/90\). First Mac with SCSI, memory expansion. Longest model life - over 4 years.
That had us most of the way there, but we still needed to add quote marks at the start and end of each line, so we had BBEdit search for \r and replace it with "\r". Three fields down; one to go.
- "compact/plus.shtml", "Mac Plus", "\(1/86-10/90\). First Mac with SCSI, memory expansion. Longest model life - over 4 years."
Next we manually numbered every line in our database. The Mac Plus is the 27th in our list, so the entry now looked like this:
- "27", "compact/plus.shtml", "Mac Plus", "\(1/86-10/90\). First Mac with SCSI, memory expansion. Longest model life - over 4 years."
Brian and I had created 89 records that were just about ready to be imported into the MySQL database we'd created. Just a couple more steps. We needed to preface each line with INSERT INTO mod (id,link,model,text) VALUES( and append ); to the end of the line. Again, we did a search for the return (\r in BBEdit) and replaced it with );\rINSERT INTO mod (id,link,model,text) VALUES( - resulting in the following
- INSERT INTO mod (id,link,model,text) VALUES("27", "compact/plus.shtml", "Mac Plus", "\(1/86-10/90\). First Mac with SCSI, memory expansion. Longest model life - over 4 years.");
It probably takes longer to explain the steps than it took to do them. Then it was time to import the whole text file into MySQL using PHPMyAdmin. It failed the first two or three times because I'd accidentally given two lines the same number.
Once the import was successful, we were done. The database had been created. Now all we needed to do was use the data to create Mac of the Day entries.
Recent Online Tech Journal Columns
- Apple's AAUI ethernet connector, 09.04. From 1991 through 1995, Apple used a proprietary ethernet connection. Why they created AAUI and where to find adapters.
- PowerPC G5: Apple's last fling with PowerPC architecture, 05.24. Teaming up with IBM, Apple adopted the PowerPC G5 in 2003 - and phased out the last G5 Power Mac three years later.
- The PowerPC G4: From 350 MHz to 2.0 GHz, 05.24. AltiVec and dual processor support made the G4 a big improvement over the earlier G3 processor.
- The PowerPC G3 story: From 233 MHz to 1.1 GHz, 05.24. The history of the PowerPC 750 family and its use in Apple computers from 1997 through 2004.
- More in the Online Tech Journal index.
Links for the Day
- Mac of the Day: iMac Core2, Sep. 2006 - Apple introduced the biggest screen ever in an iMac with a 24" Core2 Duo model at 2.16 GHz.
- List of the Day: MacBook List for those using a MacBook or MacBook Pro.
- September 6 in LEM history: 99: G4 vs. Pentium III - 00: Setting up a server - 02: Norton Utilities warning - 10 greatest computer annoyances - 06: iMac Core2 Duo - Mac mini Core Duo - The iMac Core2 value equation - 07: Apple seduction - Why I really want an iPod touch - iPod history, 2005 to present - Upgrading a Power Mac G - Apple intros iPod touch, classic, and video nano
Recent Content on Low End Mac
- Anticipation: New iPods Now, New Macs Later, Kev Kitchens, Kitchens Sync, 09.05. The season of new iPods is at hand, but new Macs may wait until 2009.
- Buy a MacBook Now or Wait?, MacBook touch Patents, Samsung X360 Takes on MBA, and More, The 'Book Review, 09.05. Also 20 years of portable Macs, data backup and preservation, universal U-Charge battery charger for Mac 'Books, bargain 'Books from $150 to $2,699, and more.
- Listen to Just the Music with the V-Moda Vibe Earbuds, Tommy Thomas, Welcome to Macintosh, 09.05. Well built, the noise canceling earbuds will let you hear all the nuances of your music without letting through background noise.
- Source of iPhone 3G Problems, Army Uses iPods as Field Translators, Gains with Business, and More, iNews Review, 09.05. Also UK bans iPhone ad as 'misleading', iPhone password easy to bypass, GM to offer radios with USB in 2009 models, weather tracking software, and more.
- Macs Gain Ground in August, Consumers Most Likely to Buy Macs, LaCie USB Speakers, and More, Mac News Review, 09.05. Also migrating Time Machine to a new drive and two new keyboards from Logitech.
- Best iPod touch Deals, Low End Mac Deals, 09.05. Refurb 8 GB, $199; new, $284; refurb 16 GB, $299; new, $370; refurb 32 GB, $399; new, $453.
- Best 15" MacBook Pro Deals, Low End Mac Deals, 09.05. Used 1.83 GHz Core Duo, $999; 2.16, $1,125; new, 2.2, $1,450 after rebate; refurb 2.4, $1,699; 2.5, $1,999; 2.6 Santa Rosa, $1,849; rebates on new.
- Best iMac G4 Deals, Low End Mac Deals, 09.05. Used 15" 700 MHz CD-RW, $279; 800 Combo, $300; 1 GHz $390; 17" 800 MHz SD, $439; 1.25 GHz, $449; 20", $569.
- Overclocking a Mac mini Got Me Hooked on Souping Up Macs, Adam Geller, My First Mac, 09.04. Stories of hot rodding iBooks, G3 iMacs, and PCI Power Macs on the cheap.
- Apple Will Not Abandon Optical Drives, the Mac Drought, Purposeful Mac Acquisition, and More, Dan Knight, Low End Mac Mailbag, 09.04. Also Mac OS X 10.5 on a G4-upgraded Blue & White G3 and problems using a flat panel display with a Quadra 700.
- Only Leopard Runs Routine Maintenance Tasks after Startup or Waking from Sleep, Charles W. Moore, Miscellaneous Ramblings, 09.04. Mac OS X 10.5 runs routine system maintenance scripts as soon as possible after starting up or waking up your Mac. Earlier versions of OS X do not do this.
- Tomorrow's Solid State Drives and Notebooks, Dan Knight, Mac Musings, 09.04. Flash drives are great but have some shortcomings. Some thoughts on building better SSDs and notebooks to use them.
- Best Mac mini Deals, Low End Mac Deals, 09.04. Used 1.25 GHz G4 SD, $549; 1.42 Combo, $409; new 1.83 Core2 Combo, $569 after rebate; 2.0 SD, $769 after rebate.
- Best 12" PowerBook G4 Deals, Low End Mac Deals, 09.04. Used 867 MHz Combo, no APX, $490; 1 GHz, $550; SuperDrive, $625; 1.5 GHz w/o APX, $660; w/APX, $675.
- Best 17" PowerBook G4 Deals, Low End Mac Deals, 09.04. Used 1 GHz, $779; 1.33 GHz, $799; 1.5 GHz, $859; 1.67 GHz, $910.
- 11 Mac Browsers Compared, Simon Royal, Mac Spectrum, 09.03. The latest versions of Internet Explorer, Opera, Safari, Shiira, iCab, Radon, Firefox, Netscape Navigator, SeaMonkey, Flock, and Camino tested in Leopard.
- Save Internet Radio, USB and Hard Drives, Hardware Manufacturers vs. Linux, and More, Dan Knight, Low End Mac Mailbag, 09.03. Also Mac won't book after cleaning, newer versions of OS X improve wake from sleep, downgrading to OS 8.6, unreadable pages on Low End Mac, and more.
- Another Free POP3 Provider, Recharging a Dead PRAM Battery, Current Kanga Value, and More, Charles W. Moore, Miscellaneous Ramblings, 09.03. GMX email now available in US, Panasonic UJ-841S drive won't burn discs, restoring a dead PRAM battery in a Pismo, and thoughts on Kanga value today.
- Best eMac Deals, Low End Mac Deals, 09.03. Used 700 MHz Combo, $120; 1.25 GHz SuperDrive, $150; 1.42 GHz, $349.
- Best Mac OS X 10.5 'Leopard' Deals, Low End Mac Deals, 09.03. Mac OS X 10.5, single user, $99; 5 users, $140; 10.5 Server, 10 users, $395; unlimited, $850.
- Best MacBook Air Deals, Low End Mac Deals, 09.03. Refurb 1.6 HD, $1,499; new, $1,690 after rebate; refurb 1.8, $1,699; new, $1,919 a/r; refurb 1.6 SSD, $2,099; new, $2,294 a/r; refurb 1.8, $2,299; new, $2,400 a/r.
- Psystar Strikes Back, Countersues Apple, Frank Fox, Stop the Noiz, 09.03. Psystar is trying to paint Apple as a monopoly and force it to license the Mac OS.
- More links in our archive.
Go to the Online Tech Journal index.
About LEM | Support | Usage | Privacy | Contacts

