Penn State

Web Conference 2005

Writing PHP for ITS/ASET Web services

Saving Data on the Server

<- Back - Email Submission Form|Up |Saving Data in Files - Next ->

In addition to sending user-supplied data over email, there are times when you wish to keep the data on the server. This not only allows you to tidy up your inbox and not stress the email system with too much data, but allows you to reuse the data on the site. Interactive sites, registration forms, bulletin boards and many other applications can benefit from such a flow of data.

Types of server-side data storage include:

namedescription accessible from php.scripts.psu.edu provided with php.scripts.psu.edu
Flat text filesFiles you access via fopen(), fread(), fwrite(), fscanf(), file_get_contents(), file_put_contents(), etc, in a format you build yourself.YesYes
SQLite database filesFiles you access via sqlite_open(), sqlite_query(), sqlite_fetch_array(), etc; an SQL92 compliant method of accessing files like databases.YesYes
MySQLA relational database server that you may access via mysql_connect(), mysql_query(), mysql_fetch_array(), etc. The most popular database used with PHP.YesNo
PostgreSQLA relational database server that you may access via pg_connect(), pg_query(), pg_fetch_array(), etc.YesNo
DB2A relational database server that you may access via odbc_connect(), odbc_exec(), odbc_fetch_array(), etc or db2_connect(), db2_exec(), db2_fetch_array(), etc.Not yetHopefully soon

Accessing files directly, as described in the "Flat text files" section above, is the old-fashioned method of storing data on the server. Back in the heyday of Perl and CGI this was the most popular method used. Since PHP grew up with databases being the norm, most applications available for PHP require use of a database, such as MySQL. Both Perl and PHP may access both plain files and databases. This lesson describes activities on doing both from PHP.

 Unfortunately, there is no fully-featured database service provided for php.scripts.psu.edu at the time of this tutorial. Our exercises will utilize SQLite, a database-like way of accessing files. It is our aim to find and appropriate a database server for use by php.scripts.psu.edu in the not-too-distant future.

Using files

Using SQLite

Tips for using a remote database

<- Back - Email Submission Form|Up |Saving Data in Files - Next ->

If you have any questions, feel free to ask me.

Content by: Jeff D'Angelo <jcd@psu.edu> © 2005

See the source for this page

Last update on: Mon Jun 13, 2005, 12:54:54 AM