Low End Mac's Online Tech Journal

Creating Your My SQL Database

Website Automation with PHP and MySQL, Part 2

Low End Mac Reader Specials

Memory To Go Special: MacPro 8 Core Memory 4GB kit $192 / 2GB kit $109. MacBook Pro / MacMini / iMac Intel Core2 DUO 2GB $44 1GB $23--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: LA Computer Company: Specials on AppleCare, Apple Displays, MacBooks, iMac's, MacBook Pros, Laptop and iPod accessories and more. Apple A/C Adapters for laptops starting at $25.00 Call 1-800-941-7654 or Click Here.

OtherWorld Computing: Better than new Batteries for iPods NewerTech NuPower, up to 20+ Hours! Complete with Tools from $19.99. Online videos. Professional installation available.

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.

MacPro Memory 667Mhz With Apple Spec Heat Sink 2GB Kit $ 90 / 4GB Kit $140 / 8GB Kit $278 Click to Maximize your Macs...

Dan Knight - 2002.04.24

What is PHP? I can't summarize it any better than Try a New Language: PHP:

PHP is an open-source, server-side, cross-platform scripting language that is used to generate dynamic Web pages or to build browser-based applications. The PHP script can be embedded in the HTML page to generate HTML code that is inserted in the Web page at that point, or the PHP script can generate the entire HTML output. One of PHP's strengths is easy database integration.

That database integration usually comes from a MySQL database, another open-source standard. For our purposes, creating a database will be the first thing we do - before we even begin programming in PHP. (And it's all free.)

Creating the Mac of the Day Database

The first piece of Low End Mac we be automated was the Mac of the Day. I have a list of nearly 100 Apple models and clones, along with a page link and a brief note on the model's significance. Here's what the Mac Plus entry looks like in HTML:

<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 could create a database containing that entire text string or create one with separate fields for the link, the model name, and the description. Neither system is inherently better than the other, but using three fields will create a system where editing the description could be done with no risk of messing up the link or the model name. It will also have a second benefit, which I'll mention later.

MySQL has three types of string or text records. (Other record types are numeric and time-related.) The CHAR type uses fixed length strings, while VARCHAR allows variable string lengths. Although that's a more efficient use of space, VARCHAR adds overhead and reduces performance. Both of these field types are limited to 255 characters, which will be plenty for our needs.

The third string record is BLOB or TEXT fields, which can be as large as 65,535 characters. We might use such fields when we work with mailing lists and articles, but we don't need such large fields right now.

The longest model name is under 30 characters, and the longest link is just over 20 characters, so we'll give ourselves a bit of room and give the model name field a maximum length of 32 and the link a maximum size of 24 characters.

A few of the descriptions are around 100 characters, so we'll set the maximum size for that text field to 128 characters.

To create the database, you'll need to log into the MySQL server you'll be using. Your ISP or system administrator should be able to provide all the information you need to do that. If you're using Telnet, type the following at the prompt to create your database:

mysql> create database macs;

This creates an empty database named "macs" - and it's just waiting for us to create a table for our data. We'll be creating the following fields:

mysql> CREATE TABLE mod (
-> id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> link CHAR(24),
-> model CHAR(32),
-> text CHAR(128),
-> );

The first line creates a table called "mod" (Mac of the Day") within our database. The first field gives each record a unique and automatically created ID number with a maximum value way up there in the billions. PRIMARY KEY declares id as the primary field in this table, meaning it is the one MySQL will index and access most readily.

NOTE: I didn't do it this way. My son Brian <http://brkn.net/> told me about a program called PHPMyAdmin that's much easier than using Telnet.

All that remains is to move the data from my current HTML file into MySQL.

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.

LEM

Recent Online Tech Journal Columns

Recent Content on Low End Mac

Go to the Online Tech Journal index.

About LEM | Support | Usage | Privacy | Contacts


Have a question?
Ask an expert!

Low End Living

Amazon.com

Navigation

Used Mac Dealers
Apple History
Best Used Macs
Video Cards
Email Lists
InfoMac's Low
End Mac Forum

Favorite Sites

MacSurfer
MacMinute
MacInTouch
MyAppleMenu
InfoMac
Macs Only!
The Mac Observer
Accelerate Your Mac
RetroMacCast
PB Central
MacWindows
The Vintage Mac
   Museum

DealMac
DealsOnTheWeb
Mac2Sell
ramseeker
Mac Driver Museum
JAG's House
System 6 Heaven
System 7 Today
the pickle's Low-End
   Mac FAQ

Abandonware
   Petition

Mac vs. PC Info

Affiliates

The Apple Store
Mac Connection
MacMall
TechRestore
MacResQ
ExperCom
Crucial Memory
batteries.com

Advertise

Open Link