Pages

Monday, December 8, 2003

Accessing SQL Databases in HTML::Mason

Introduction

In the past 3 articles, we discussed about the different components of HTML::Mason. Most web sites require database access so when you create your HTML::Mason pages, you should also consider this.

Data base access in HTML::Mason

Accessing database in HTML::Mason is similar to accessing it in an ordinary Perl script. Let's say you have a database called article and you want to list all the rows in the article table. Assuming that your database is MySQL, you would do this in an ordinary Perl script:

In HTML::Mason, you also need to connect to your database and issue SQL statements. If you have only one page that will require database access, you can hard code the connection statement. However, if you have 10 pages that require database access, you can still hard code the connection statement. But if you need to change the userid or password, you will need to change them in all these pages.