Database Reference
In-Depth Information
client request, sends results back to the browser, and forgets about the interaction with that
client. A second request from that same client is treated as a new request from a new client. No
data are kept to maintain a session or connection with the client.
This characteristic poses no problem for serving content, either static Web pages or
responses to queries of a database. However, it is not acceptable for applications that require
multiple database actions in an atomic transaction. Recall from Chapter 6 that in some cases, a
group of database actions needs to be grouped into a transaction, with all of them committed to
the database or none of them committed to the database. In this case, the Web server or other
program must augment the base capabilities of HTTP.
For example, IIS provides features and functions for maintaining data about sessions be-
tween multiple HTTP requests and responses. Using these features and functions, the applica-
tion program on the Web server can save data to and from the browser. A particular session
will be associated with a particular set of data. In this way, the application program can start
a transaction, conduct multiple interactions with the user at the browser, make intermediate
changes to the database, and commit or roll back all changes when ending the transaction.
Other means are used to provide for sessions and session data with Apache.
In some cases, the application programs must create their own methods for tracking session
data. PHP does include support for sessions—see the PHP documentation for more information.
The particulars of session management are beyond the scope of this chapter. However,
you should be aware that HTTP is stateless, and, regardless of the Web server, additional code
must be added to database applications to enable transaction processing.
Web Page Examples with PhP
The following three examples extend our discussion of using PHP Web pages in Web database
applications. These examples focus mainly on the use of PHP and not as much on the graphics,
presentation, or workflow. If you want a flashy, better-behaving application, you should be able
to modify these examples to obtain that result. Here, just learn how PHP is used.
All of these examples process the View Ridge Gallery database. In all of them we use the VRG
database in each DBMS as we constructed it for SQL Server 2012, Oracle Database 11 g Release 2,
and MySQL 5.6 in Chapters 10A, 10B, and 10C, respectively. For simplicity, we connect to each
using an ODBC system data source—VRG for SQL Server, VRG-Oracle for Oracle Database and
VRG-MySQL for MySQL. And if we use the same user name and password in each DBMS, we need
to only change the ODBC data source name to switch between DBMSs! That is amazing, and ex-
actly what the originators of ODBC hoped for when they created the ODBC specification.
Note, however, that although we are using ODBC functions, PHP actually provides a spe-
cific set for most DBMS products. These sets are generally more efficient than ODBC, and if
you are working with a specific DBMS, you will want to explore the PHP function set for it. 8 As
an example of this, note that we connected to the database using:
// Get connection
$DSN = "VRG";
$User = "VRG-User";
$Password = "VRG-User+password";
$Conn = odbc_connect($DSN, $User, $Password);
If we are using MySQL, however, we can use:
// Get connection
$Host = "localhost";
$User = "VRG-User";
$Password = "VRG-User+password";
$Database = "VRG";
$Conn = mysqli_connect($Host, $User, $Password, $Database);
8 Microsoft has created an updated set of functions for SQL Server. If you are going to use the SQL Server-
specific functions, you should download the Microsoft Drivers 3.0 for PHP for SQL Server from http://www
.microsoft.com/en-us/download/details.aspx?id=20098 , which also includes the documentation.
 
 
 
Search WWH ::




Custom Search