The Webslave's Handbook
by Marcus Del Greco
Introduction
Basic Web Architecture
The Front End
The Back End
- Perl
- MySQL
- Why a Database?
- Why MySQL?
- MySQL inside perl
- Getting Started in MySQL
- basic admin
- Perl DBI:MySQL
- connecting to your database
- creating, preparing, and executing SQL statements
- data types including varchar and int
- self-incrementing columns
- null vs. not null
- the blob types
- creating tables at the command line
- altering tables (adding and removing columns)
- deleting tables (deleting all contents vs. removing the table definition)
- showing and describing tables
- Down to business with simple SQL (Structured Query Language)
- SELECT
- simple SELECT query and FROM
- talking between tables - using SELECT qualified by WHERE
- compound WHERE qualifier
- further qualifying SELECT with ORDER BY()
- compound ORDER BY()
- determining data size with length()
- looping through returned records with while and fetchrow_array()
- get MySQL standard datetime with SELECT NOW()
- INSERT
- UPDATE
- DELETE
Introduction
There Are No Webmasters
When the web was being born in the 1990s, the people birthing it seized on the
opportunity to establish a standard by which their own jobs would be titled. In
the excitement of the moment all humility was forgotten and the term "webmaster"
was chosen. Now web developers and administrators are saddled with a mighty
moniker to live up to... but is it possible?
Not long after "webmaster" became common a sly rebuttle started floating
around the net... "there are no webmasters". This was obviously
from webmasters themselves, humility now remembered. It seemed the act
of building and running a website was not so simple as it seemed, and true mastery
of the medium in all its facets was something few could claim. In
addition, the sheer hours invested in keeping the sites alive gave some the sense
that the web was a beast growing out of control... something not so much to be
mastered, but at a minimum, tamed.
Developing for the web can be a complex undertaking because of the many technologies
involved. Each problem or task can suggest several different possible avenues
for solution, making use of multiple programming languages or syntaxes that require
a working knowledge. Not an evening's worth of labor. Reading this
now, you have probably already realized the challenge ahead of you. The
more time you are willing to invest, the more you will feel like a master. Let's
start learning how to tame the web.
Master of None
Ever heard the expression "Jack of all trades, master of none"?
This is what a webmaster needs to be. Many skills are required to build
a website, and if you were to become a legitimate expert in each before making
a site, you'd have to wait ten years.
That's why we need to take the pressure off a bit. You'll be learning lots
of new things, each of which falls into a separate category, and you'll build
your knowledge of each incrementally as you go. Over time you will become
a Jack of all trades, with various tools in your belt, handy in various situations.
Don't worry about becoming a master... there are no webmasters... a broad
range of understanding will serve you best in the web environment.
Scope of this Book
In this book I share with you the tools I have managed to add to my own toolbelt
over the past 5 years. They are by no means the full set of tools available
to you as a web developer. The main topics covered here are HTML, CSS, Javascript,
Perl and MySQL. There are a host of other languages to choose from when
writing more complex applications for the web. But the concepts covered in
this book should provide you solid options in the course of your development.
I have chosen Perl/MySQL for my independent web projects because they are
essentielly free technologies for the small operation, and also because they offer
a somewhat lower learning threshold than, for instance, using full object oriented
design with Java or C++.
A Thin Veil
As you might suspect, this book is going to talk a great deal about that dreaded
word.... code. Most computer users, myself included, start off intimidated
by that word. All the code you ever see looks foreign and cryptic,
how can you ever understand it? Why in the world would you want to?
Code lies beneath everything you've ever seen or done on a computer. Millions
and millions of lines of code. When you realize what an immense task
programming can be, and all the intricacies behind what has been done, it is staggering
the work that has gone into delivering us the functionality we enjoy on personal
computers today.
The images you see on your screen are but a thin veil between you, the user, and
a whole lot of code. That's why when things go awry on your computer, you
are so likely to encounter a mind-boggling error message referring to a fatal
error on line #237 or something. The code has failed to handle some
event and is trying to tell you about it.... as though you were the developer
and could do something about it.
But when when you are the developer line #237 might well mean something to you.
You would open your program and examine that line, looking for bad syntax
or other such gremlins. Hopefully you'll be able to go "beneath
the veil" after reading this book, and actually speak some of the languages
of the web enough to recognize what you see under there.
Basic Web Architecture
Uniform Resource Locators (URLs)
They sound fancy but they're not: they're simply the way we find things on
the web. They are the addresses that begin with http:// and eventually
end in some file name or some other fancy looking string of characters. A
URL can begin with an IP address...
http://216.239.51.100
...or, more commonly, a domain name:
http://www.google.com
In this case, both URLs will get you to the same place, because 216.239.51.100
is the IP address for google.com. The association of domain names to IP
addresses is made by DNS (Domain Name Servers) so that we can all enjoy easy
to remember names for our websites instead of digits.
HTTP stands for Hypertext Transfer Protocol, the kind of communication a webserver
listens for.
Webservers
A webserver is software which listens for incoming http requests and responds
by transfering the requested files (and associated files) over the network to
the web browser. There are many makes of webserver software but by far the
most popular is Apache, which runs on UNIX and Linux operating systems. This
book does not cover webserver administration, but it does recommend Apache when
choosing webhosts.
Webhosts
A webhost is the best friend of a webmaster. Webhosts are businesses which
provide all your basic webserver resources at a monthly fee in order for you to
get your site on the world wide web. They take care of all the nasty details
involved in configuring the webserver software, installing other software, partitioning
their disk space, etc, etc... things you would have to do instead of working on
your website. The services of these companies (the good ones) are worth
every penny and it is highly recommended that you begin any website venture by
outsourcing you webhosting in this way. Unless you are a major corporation,
or just really into hosting your own site at home, get your site hosted by a reputable
service provider. They will help you register your domain name and take
care of the DNS details mentioned above that you won't want to deal with on your
own.
Browsers
You have never seen a webpage as intended but through a piece of software known
as a browser. It is the client portion of the client-server relationship
for which we have already discussed the server portion. Just as there are
many varieties of webserver software, there are many varities of browser software...
and a most popular. Microsoft's Internet Explorer is the most
popular browser, by far, as of this writing. This is because of the
sly practice of tying the browser closely to the desktop operating system, Microsoft
Windows, also most popular in its class currently.
But Microsoft is not the only developer of browser software, and those surfing
using Netscape or anything in the "Other" category (including Opera
and Mozilla, a Netscape offshoot project) represent a significant percentage of
your browsership.
What do we care which browsers our surfing audience may be using? Have a
seat and brace for some bad news, because this is some of the worst news a developer
can get. Browser client applications process code in different ways
and often your webpage which looks great in one browser craps out in another.
This problem becomes most troublesome when dealing with Javascript, a language
which has suffered the worst from attempted standards making and standards breaking
of any I have seen.
That's why the most important thing for a web develop to know about browser is
that you need to test in more than one. Load one or more (ideally)
alternate web browsers on your computer and fully test your website for aesthetics
and functionality in each one. The results may disappoint you, and you
will have to make a judgement call. Is this aberration acceptable? Can
I live with this difference for my [insert browser here] users? If
not, you'll need to hit the net or your favorite book to work out the compatibility
problem.
In this book I attempt to present only HTML, CSS and Javascript code which is
compatible with the two main browsers, Internet Explorer and Netscape.
With luck this will help you prevent running into any problems right away. But
eventually, the more functionality you develop on the client side, the more you
will have to deal with browser compatibility issues.
</bad news> :)
Front End vs. Back End
Don't be gross. This section is about how the developer sees a client-server
application like the world wide web. Most web developers start off conceiving
of their site as primarily a "front end" object. In other words,
all the "action" is on the client side, where the user is viewing
the webpage on her browser. You layout the words and images which comprise
the main experience of visiting the website. This is essentielly done
with HTML and Javascript, as well as other tools like CSS. Your pages
in these languages are downloaded to the web browser and processed on the user's
computer.
If this is the front end, what is the back? The back is your webserver,
and the kicker is, you can elect to do processing there if you like as
well. This turns out to be an immensely powerful option with potential
to greatly simplify a webmaster's daily tasks. Writing programs for the
back end of your website is the Holy Grail of the beginning developer and I
hope you will pursue it and know the joys of conquering it.
***
On to The Front End
Back to top
copyright 2004 Marcus
Del Greco