Latest Stories

A database driven website is a website that has most of its webpage content in a database. Therefore, the website content isn't actually sitting in files on the server, it is sitting in tables and columns in a database.

A website with its content stored on the file system is often referred to as a static website, whereas a database driven website is often referred to as a dynamic.
 
Content Management Systems

A website with dynamic content usually has a CMS (Content Management System) to assist the content providers in updating the website.

A CMS is usually provided in the form of an administration area where content providers need to log in before they can add content. Once logged in, they can create, update and delete articles. They may be able to upload files such as Word documents, PDF files etc. They might be able to upload images too.

All of this content can be stored in the database. Some may be stored on the file system too though. For example, although documents and images can be stored in the database, there are sometimes reasons to store them on the file system. Performance is often a key reason. Database size is another.
Discussion Forums and Blogs

Discussion forums and blogs have become a popular feature for many websites. Most, if not all, forums and blogs are database driven. Users can register their details, then add content. When the user clicks the "Submit" button, their details/content is inserted into the database. Then when someone decides to view this content, it is read from the database using SQL (Structured Query Language).
Combination of Static and Dynamic

Some websites have a combination of static content and dynamic content. There could be any number of reasons for this. Often, smaller websites will be static. There's little need to configure a database just to store a handful of webpages - much easier and cheaper to keep them as files on the server. Even websites like this might contain some added functionality such as a discussion forum, or a blog. In this case, the discussion forum or blog will need its content stored in a database.
Benefits of a Database Driven Website

Database driven websites can provide much more functionality than a static site can. Extended functionality could include:

Enabling many (potentially non-technical) users to provide content for the website. Users can publish articles on the website without needing to FTP them to a web server.
 
Shopping cart
You can provide advanced search functionality that enables users to filter the results based on a given field. They can then sort those results by a field - say "Price" or "Date".
 
Customized homepage
You can allow your users to perform tasks such as registering for a newsletter, post questions to your forums, provide comments on a blog, update their profile, etc.
Integration with corporate applications such as CRM systems, HR systems etc
Read More ...

Latest Stories

With database management systems, many tasks can be done either via programatically or a user interface. Creating databases is no exception.

Option 1: Programatically

Many database administrators (DBAs) use Structured Query Language (SQL) to perform many of their database tasks. To enter SQL, you need to open an interface that allows you to enter your code. For example, if you use SQL Server, you would normally use Query Analyzer.
The following example is the basic code for creating a new database. Parameters can be added to this example if your requirements are more specific.
CREATE DATABASE MyDatabase
Note: This example assumes you know how to use your database system to run scripts like this. If you don't you, will probably find it easier to use the user interface method (below).

Option 2: User Interface

Most database systems make it very easy to create a database via a user interface. Generally, it's just a matter of selecting an option from a menu, then providing a name for your database.
The following examples demonstrate how to create a database in Microsoft Access.
  1. From the "File" menu, click on "New Database":
    Creating a new database in Access - step 1
  2. Choose "Blank Database". (MS Access also gives you the ability to choose from a template, but we'll just use a blank database here):
    Creating a new database in Access - step 2
  3. Choose a location to save the database:
    Creating a new database in Access - step 3

Your New Database

Once you've completed the above tasks, you should see a blank database, like this:
Creating a new database in Access - step 4 We know this database is blank because it doesn't have any tables. If it did, you would see these tables in the middle pane of the table tab. Now that we have our blank database, we can start adding some tables.
Read More ...

Latest Stories

In the previous lesson we created a datasource so that it could be used by ColdFusion to connect to a database.

Now that we have the datasource, we can perform a query against the database that the datasource is linking to. To perform a database query in ColdFusion, you use the cfquery tag.

Basic CFQUERY Example


This code is all you need to do in order to query a database in ColdFusion. The cfquery tag connects to and opens the database for you, all you need to do is supply it with the name of the datasource.

<cfquery datasource="Entertainment">
select *
from Movies
</cfquery>

Authentication

Many database configurations require authentication (in the form of a username and password) before you can query the database. You can supply these using the username and password attributes.

Note that the username and password can also be configured against the datasource in the ColdFusion Administrator. Supplying these details in your query overrides the username and password in the ColdFusion Administrator.

<cfquery datasource="Entertainment" username="webuser" password="letmein">
select *
from Movies
</cfquery>


Cached Queries

If you have a lot of traffic, you may find that performance of your website/application is affected. If so, you will need to look at ways of improving performance. One effective technique you can use is to cache some of your database queries.

A cached query is a query that has its results stored in the server's memory. The results are stored when the query is first run. From then on, whenever that query is requested again, ColdFusion will retrieve the results from memory.

For ColdFusion, it's much faster retrieving the results from memory than to perform another query from the database. When you query a database, ColdFusion has to wait whilst the database connection (often on another server) is established, the database is opened, the query is run, and the results are returned to ColdFusion. All this takes time, and it can impact on other ColdFusion requests occurring at the same time.

You can cache a query using the cachedAfter attribute. If the query was last run after the supplied date, cached data is used. Otherwise the query is re-run.

<cfquery datasource="Entertainment" cachedAfter="November 20, 2006">
select *
from Movies
</cfquery>


You can also cache a query using the cachedWithin attribute in conjunction with the CreateTimeSpan function.

In the following example, if the query's cached data is older than 1 hour, the query is re-run. Otherwise, cached data is used.

<cfquery datasource="Entertainment" cachedwithin="#CreateTimeSpan(0,1,0,0)#">
select *
from Movies
</cfquery>

Limiting the Number of Records Returned

You can limit the number of rows to be returned by using the maxrows attribute.

<cfquery datasource="Entertainment" maxrows="50">
select *
from Movies
</cfquery>

Timeouts

You can set a timeout limit using the timeout attribute. This can be useful in preventing requests running far longer than they should and impacting on the whole application as a result.

The timeout attribute sets the maximum number of seconds that each action of a query is allowed to execute before returning an error.

<cfquery datasource="Entertainment" timeout="30">
select *
from Movies
</cfquery>
Read More ...

Latest Stories

You use PHP if statements when you want your program to execute a block of code only if a particular condition is true. In other words, you can tell your program "if something is true, then execute this piece of code".

Syntax

if (condition)
  code to be executed if condition is true;

Example

In the following example, we create a variable called "favoriteFruit" and assign a value to it. We then compare the value with a string: "Pomegranate". If the two values are the same, we output some text.
The two equals signs (==) is a comparison operator (it compares the two values). If this condition is true, it displays the code within the curly braces ({ and }). The curly braces are only necessary if you're outputting multiple lines of code . If you're only outputting one line of code (like we are) they're optional.
$favoriteFruit = "Pomegranate";
if ( $favoriteFruit == "Pomegranate" )
  {
  echo "Your favorite fruit contains around 7% fibre.";
  }
The above example results in the following:
Your favorite fruit contains around 7% fibre.

If Else Statement

We can add an else to our if statement to make our application do something else if the condition is not true.
Example:
$favoriteFruit = "Fig";
  if ( $favoriteFruit == "Pomegranate" )
    {
    echo "Your favorite fruit contains around 7% fibre.";
    }
  else
    {
    echo "Sorry, I don't know how much fibre that fruit contains.";
    }
The above example results in the following:
Sorry, I don't know how much fibre that fruit contains.

If... Elseif Statement

Let's say we learn the fibre content of another fruit. We could then add an elseif to our if statement. That way, we could include a custom message for the new fruit. In fact, we could use elseif as many times as we like.
Example:
$favoriteFruit = "Lychee";
  if ( $favoriteFruit == "Pomegranate" )
    {
    echo "Your favorite fruit contains around 7% fibre.";
    }
  elseif ( $favoriteFruit == "Lychee" )
    {
    echo "Your favorite fruit contains around 1.5% fibre.";
    }
  else
    {
    echo "Sorry, I don't know how much fibre that fruit contains";
    }
The above example results in the following:
Your favorite fruit contains around 1.5% fibre.
Read More ...