Database Driven Websites Edit
Many websites are directly connected to a database that stores important data about the site. Every time the webpage is refreshed, information such as content, links, images, etc. is called from the database and implemented into the site. Without databases, search engines, banking sites, email, etc. would not be able to function properly.
As mentioned before, with a database driven website, information stored in a database is extracted from the database every time the page is refreshed. This is called dynamic updating; meaning updating is performed at runtime. Sites without the use of databases are called static (unchanging) because every time the page is loaded the user sees the same content. Updating a website through a database is much easier than hard coding content into every page. Imagine having to manually update a banking website. The web programmer would have to change millions of accounts by hand which wastes time, money, and compromises both the accuracy and security of the data.
Another advantage of a database driven website is that the site updater does not necessarily need to see or work with a web programming language (such as html). Programming can be confusing if you don’t know what you are doing, so it is important to keep it simple. Also, instead of making multiple updates of the same content, databases allow the person who updates the site to enter the data once, and then it can be displayed in multiple places on the site.
Website users can enter data into forms on the site to be stored in a database. This is achieved through SQL statements.
Since most of the sites’ content is stored in one place, a site will not function if the database is not running properly. This is why security and backups are important when using a database driven website.
SQL Statements Edit
In order for data to be extracted from or inserted into a database there are certain statements, called SQL (Structured Query Langauge) statements, that need to be programmed into the site. SQL statements interact directly with the database allowing data to be selected, updated, inserted, and deleted.
Example SQL statements
In these examples, the SQL statements are interacting with a database that stores account information for a banking website.
Select Statement: Select statements find specific data in the database and put it into the site so it can be manipulated and/or displayed.
SELECT Number, Balance
- This statement extracts the account number and balance from the Accounts table to be used on the site.
Insert Statement: Insert statements take the data that has been entered into a form on the website and put it into a specific place in the database.
INSERT INTO Accounts (Name, Deposit)
- This statement takes the name and deposit amount from the website user and inserts it into the Accounts table.
Update Statement: Update statements act like an insert statement, except they update specific cells that already exist.
SET Name = “Bob”
WHERE Number = “1234567”
- This statement would change the name field (which already exists) to Bob where the account number is 1234567 in the Accounts table. The values “Bob” and “1234567” can be replaced with variables allowing the user to update their information.
Delete Statement: Delete statements delete specified data.
DELETE FROM Accounts
WHERE Name = “Bob”
- This statement would delete the name Bob from the Accounts table. The value of Bob can be replaced with variables.