Database Reference
In-Depth Information
Now if you use the URL http://localhost/DBP/VRG in your Web browser and then click the
Example 1: Display the ARTIST Table (No surrogate key) link on that page, the Web page
shown in Figure 11-33 is displayed.
The ReadArtist.php code blends HTML (executed on the user's workstation) and PHP
statements (executed on the Web server). In Figure 11-30, the statements included between
the ?php and? tags are program code that is to be executed on the Web server computer. All
the rest of the code is HTML that is generated and sent to the browser client. In Figure 11-30,
the statements:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<CDT>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>ReadArtist</title>
<style type="text/css">
h1 {text-align: center; color: blue}
h2 {font-family: Ariel, sans-serif; text-align:
left; color: blue}
p.footer {text-align: center}
table.output {font-family: Ariel, sans-serif}
</style>
</head>
<body>
are normal HTML code. When sent to the browser, these statements set the title of the
browser window to ReadArtist; define styles to be used by the headings, 6 the results table, and
the footer; and cause other HTML-related actions. The next group of statements are included
between and, thus, are PHP code that will be executed on the Web server. Also note that all
PHP statements, like SQL statements, must end with a semicolon (;).
Creating a Connection to the Database
In the HTML and PHP code in Figure 11-31, the following PHP code is embedded in the HTML
code to create and test a connection to the database:
<?php
// Get connection
$DSN = "VRG";
$User = "VRG-User";
$Password = "VRG-User+password";
$Conn = odbc_connect($DSN, $User, $Password);
// Test connection
if (!$Conn)
{
exit ("ODBC Connection Failed: " . $Conn);
}
After it runs, the variable $Conn can be used to connect to the ODBC data source VRG. Note
that all PHP variables start with the dollar sign symbol ($).
6 Styles are used to control the visual presentation of the Web page and are defined in the HTML section be-
tween the <style> and </style> tags. For more information about styles, see David Raggett's “Adding a Touch of
Style” tutorial at www.w3.org/MarkUp/Guide/Style.html .
 
Search WWH ::




Custom Search