This column has been looking at ways to simplify the development of a database-driven Web-based address book. Now we look at a complete solution: the PostgreSQL Object Relational Database Management System (ORDBMS).
The Structured Query Language (SQL) was developed to be a language-driven interface to data management. The most recent standard is SQL99. SQL allows database users to treat data in terms of set theory, which is a school of mathematics focusing on grouping data into sets and building relationships between these sets.
PostgreSQL
This is a leading open source database that supports much of SQL99. The PostgreSQL source code can be downloaded from http://www.postgresql.org. You will need access to a UNIX machine (Linux, BSD, Solaris, etc.) to install it. The installation process is described in detail in the 'INSTALL' file in the top level directory of the source tree.
Once you have installed PostgreSQL, you will need to recompile PHP with PostgreSQL support. For more information, see the INSTALL file in the top level directory of the PHP source tree as well as the output of ./configure --help.
Creating A Database
Once you have installed PostgreSQL, log in to your UNIX system as the database superuser. Then type:
$ /usr/local/pgsql/bin/psql template1
...
template1=#
Where '$' is the shell prompt and 'template1=#' is an SQL prompt. This will connect you to the pre-existing PostgreSQL database. You can then create another database.
template1=# CREATE DATABASE phphh;
CREATE DATABASE
template1=# \c phphh
phphh=#
On the first line of input, we create the database 'phphh'. The second line is feedback from the database backend that the database was correctly created. The third line sees us connecting to the new database with the \c connect command (note that this third line is not SQL, it is a command to the psql program we are using). The fourth line shows us connected to the new database.
Creating A Table
SQL databases store data in tables or 'relations'. If we wanted to create a table called 'test' with three columns a, b and c, we could do the following:
phphh=# CREATE TABLE test ( a int, b text, c text);
CREATE
phphh=#
We now have a table in which we can insert, update, delete and retrieve data.
Inserting Data
This is done via INSERT. An example follows:
phphh=# INSERT INTO test VALUES(1,'test1','test2');
INSERT 50441 1
phphh=#
The line 'INSERT 50441 1' indicates that the row was correctly inserted, that it is the 50441st insert and that a single row ('1') was inserted.
Retrieving Data
This is done via SELECT. An example follows:
phphh=# SELECT * FROM test;
a | b | c
---+-------+-------
1 | test1 | test2
(1 row)
phphh=#
Using SELECT, we are able to retrieve the data we just inserted. Notice how this parallels the concept of the spreadsheet.
Deleting Data
Data is removed from a table with a DELETE query. The DELETE syntax resembles that of SELECT:
phphh=# DELETE FROM test;
DELETE 1
phphh=#
Use a SELECT to verify that the data has been removed.
Updating Rows
Updating a table is, in effect, a DELETE followed by a SELECT. This is simplified in SQL as UPDATE.
phphh=# INSERT INTO test VALUES(1,'test1','test2');
INSERT 50442 1
phphh=# UPDATE test SET a=2; UPDATE 1
phphh=# SELECT * FROM test;
a | b | c
---+-------+-------
2 | test1 | test2
(1 row)
phphh=#
Notice that the value of the column 'a' has been changed from 1 to 2.
Discover how SOA can create smarter outcomes for your business.
Attend and learn:
- How SOA is helping leading companies to become more agile
- Where you should be applying SOA processes in your company
- The top SOA implementation mistakes to avoid
Click here for more information.
- +
Computerworld Live Podcast #97: The Future of Enterprise Networking 25/07/2008 09:45:36
This week CW Live chats with Mark Thompson, global sales and marketing manager for HP ProCurve, on the future of the enterprise networking. Mark discusses the trends we can expect to see in the near future and how the right infrastructure can ensure your enterprise network is secure. - +
Computerworld Live Podcast #96: Security at the Edge 11/06/2008 09:22:22
CW Live speaks with Amol Mitra, HP ProCurve Director of Marketing for Asia Pacific and Japan. Today's topic: how enterprises are starting to shift away from simply controlling security via server logins, firewalls and moving to more adaptive security frameworks. - +
Data Management Edition #10: Multi-Petascale Systems 02/05/2008 09:12:33
This week we look at sustainability and the development of multicore technologies to build multi-petascale systems. - +
IT Security Edition #11: How to poison the Storm botnet 01/05/2008 08:51:55
This week CW Live presents a case study on how to poison the notorious Storm botnet . Plus we take a look at Cisco's plans for Ironport. - +
IT Security Edition #10: Cyber-battles fought and won 24/04/2008 11:09:47
Vendors bow to end user pressure to improve product security, and we take a look at the latest concepts shaping the cyber-battlefield of the future.
Virtual magic: HR specialist throws out 40 servers, adds 8TB SAN and saves $100,000 for disaster recovery 2008-12-01 15:28:00+11
Sybiz adds up for SMEs in downturn 2008-12-01 14:27:00+11
EXCOM scores back-to-back award trifecta 2008-12-01 10:46:00+11
Citect extends SCADA networks with mobility solutions 2008-12-01 09:48:00+11
Citect extends SCADA networks with mobility solutions 2008-12-01 09:48:00+11
Discover the advantages of an open architecture multi-vendor network solution
View this webcast and discover the drivers for changing network design practices, why many organisations are changing their approach to network architecture and how enterprises should be moving forward with open architecture multi-vendor network solutions. Register now and learn how your business can maximize the business value of the enterprise network.











