From Webmonkey.com/programming/
ColdFusion Tutorial -
Lesson 1
by Charles Mohnike
Webmaster Rule Number One
When a potential employer/client asks you if you've ever worked with XYZ
software running on platform ABC, say "yes" quickly and with great
assurance. Then run home, fire up the Net, and figure out what the hell they
were talking about.
I pulled this one a couple of years ago when interviewing
for a book publisher that used a program called ColdFusion on its site. At
first I wondered why the company needed a webmaster fluent in nuclear physics,
but a quick HotBot search revealed that
ColdFusion is a database-to-Web gateway that's turning into a very popular tool
for businesses that need to get lots and lots of data on the Web lickety-split.
And therein lies your reason to be interested in this
otherwise dry subject, because in terms of webmastering, if business likes
it, you love it. Companies with lots of junk to put on the Web usually have
budgeted lots of cash for the project, cash that they'll be more than happy to
shower upon you if you show them how to assemble a cohesive, dynamic Web site
out of their mess of databases.
ColdFusion is a tool made by Allaire that runs concurrently with most
Windows and Solaris Web servers (it can also be used effectively on intranets,
but we'll leave that for a separate tutorial and another check from the good
folks at Wired). If you host your own server in-house, you can install the
package on the same machine; if you host with an outside provider, you'll have
to convince them to purchase and install it. There's also a growing number of
Web providers offering ColdFusion as an available service. You can expect to
pay more than you would for a standard hosting account, but, as you'll read in
the next section, the time-saving properties of ColdFusion are well worth the
extra loot.
Once installed, you'll access your database with
ColdFusion templates, which look surprisingly similar to standard HTML pages.
The difference is that you can create a single template and serve up tons of
information dynamically rather than having to create a separate page for
every item. You'll need a basic knowledge of databases and HTML, and if you're
working for a client you'll need sufficient people skills to explain to them
why they need to spend money to save money.
Who Needs It?
Unless your site is a simple, two-page ode to Leo Sayer,
it's safe to say that you could save some serious man- or woman-hours by using
ColdFusion. The question is whether the time saved will justify the extra
dollars you'll shell out for the software or for the extra hosting fees your
provider will tack onto your bill. Here's a little Cosmopolitan-style
test to help you find out.
·
Do
you or your client maintain databases you'd like to see on the Web? Does the
rest of the world really need to see this data or are you maybe being just a
little delusional in thinking that we can't live without your massive archive
of bootlegged Barry Manilow performances?
·
Does
your site require frequent updates, as in, say, new products, an events
calendar, or a lengthy What's New section?
·
Do
you sell stuff on the Web?
·
Are
you the electronic equivalent of a pack rat? The sort that saves old National
Geographics and Enquirers for "future reference"? Do you
have lots of cats?
·
Do
you or your client have lots and lots of text-based documents you need to serve
up?
·
Do
you like to spend hours goofing on the Web instead of designing the site you're
supposed to be working on? Are you doing it right now and justifying it by
telling yourself that you're bettering your skills by reading Webmonkey?
·
Does
your site host banner ads?
·
Does
your site use figures that need computation, such as product totals or
inventory numbers?
Installing ColdFusion and Defining a Data Source
Installing the package is deceptively simple, and if you're an advanced enough
user that some company is giving you the administrator password and letting you
sit in the big kids' chair at their Web server then you shouldn't have any
trouble. The reason I call the process "deceptive" is that setting
this thing up is a breeze - the hard part doesn't come until later when you're
building templates.
The installer will ask you a few questions about where you
want to put the files, what Web server software you use, what program you use
to create your databases, blah blah. As before, if any of these befuddle you,
you'd better go find a grown-up to be present at the proceedings. And use those
little blunt scissors if you have to cut anything out.
You'll probably be asked to restart your machine and/or
your Web server software. If you're not the system administrator, make sure
before you restart that you have access to that little list of things you have
to do to get the server back up and running (stop and restart this process,
delete that route, etc.). Even the best sysadmins have these; they're usually
scrawled on a Post-It affixed to the monitor. Some administrators actually
print these out so they're legible, but they're usually the anal types and
probably wouldn't be letting you fool with their Web server in the first place.
Now you're ready to define your data sources in
ColdFusion. The newer versions of the software use a Web page interface to do
this and older versions use a standard Windows dialog box. Both are found under
the heading ColdFusion Administrator.
A data source name (DSN) is the database you want to serve
up on the Web. If you're running your own copy of ColdFusion, you can set up
several; if you're using it on a provider's machine you'll probably be limited
to a single DSN. Again, the setup is pretty straightforward stuff. Just point
the administrator software to the database you'll be using and, if the database
resides on a machine other than the Web server, supply any log-in and password
information it will need to log on to that machine. The key word here is permissions:
Your database should have read access enabled for the username your Web server
uses to log in. Depending on the software you use to create your databases,
this may be defined in standard file permissions or in the program itself.
Examining Your Database
This is the webmaster's equivalent of checking yourself for lumps. It's
important to scout your databases for stuff that might confuse ColdFusion
later. These include:
·
Field
names should be devoid of spaces. Use the underscore character, like new_items instead of "new items."
If your database was set up by someone else, budget some time to explain to
them why rewriting all of their database queries and macros will be worth it in
the long run. Smile as you say this.
·
Use
key fields. Most database programs set these up automatically when you create a
new table. Keys will greatly reduce the CPU time ColdFusion uses to search your
database.
·
Divide,
divide, divide. If you're running ColdFusion on your client's server, you can
use as many DSNs as you like. Use this capability by breaking up unrelated
tables into separate databases and setting up each one as an individual DSN.
Your CPU and hard drive will love you for it.
·
Check
permissions on the individual tables in your database and make sure that they
have read-access for the username your Web server uses to log in. You'll also
need to enable write-access for tables that will allow user input from the Web.
·
Make
sure that your databases, tables, and DSNs are named clearly and logically. As
a former client used to tell me, "We wanna know that if you get hit by a
bus tomorrow we can figure this thing out." There are actually two schools
of thought on this; the other is that unnecessary complexity leads to job
security.
·
If
your fields include large blocks of text, you'll want to include basic HTML
coding within the text itself, including stuff like boldface, italics, and
paragraph markers.
Review
We've covered a lot of ground today, but, if you're reading this tutorial on
the clock, you can tell your superiors it was time well spent and more than
makes up for the hours you frittered away checking your eBay auctions last week. To summarize, we
discussed:
·
How
to convince a potential client/employer that you're conversant in something you
know absolutely nothing about
·
What
ColdFusion does and why it's worth the extra bucks
·
Who
could benefit from it and who would do better to spend the money on something
else, like a shiny, new pony
·
Computer
people don't get enough sex
·
Installing
ColdFusion and setting up a DSN
·
Checking
your existing databases for ColdFusion compatibility
Next lesson we'll start creating ColdFusion templates,
talk a little about basic SQL (structured query language), and ColdFusion's tag
library. Until then, why not get up and do something else? Walk around a
little. It's fun!
Charles Mohnike is a technology writer
and the co-founder of Zapt Digital Media, an electronic publishing firm.
Copyright © 1994-2003 Wired
Digital Inc., a Lycos Network site. All rights reserved.