CMSC 4003



CMSC 4003

Lab Assignment 8: PHP and Oracle

Name:

Due: See the due date in D2L calendar.

1. Preparation

You may download lab7_schema.sql and run it in SQL*Plus. We will use some of the tables in the schema as examples.

2. Hello World!

(a) Create a file called helloworld.php using the following content:

Example 1

(b) Put the file into the public_html directory of your Web server account (sc.uco.edu)

(c) In your Web browser, check the execution of the file at:

sc.uco.edu/~gqxxx/helloworld.php

Note that “gqxxx” in the above URL should be replaced with your own account name.

(d) PHP code can be embedded in HTML code as we see in this example. PHP code is enclosed by “”. Each PHP statement ends with a semicolon (;).

Note the PHP built-in function echo(). It is used to output text strings into the resulting HTML code that is sent out by the Web Server to browsers. Therefore, the actual HTML code received by your browser does not include any PHP code. You may click on the menu item “View → Source Code” of your Web Browser to check the HTML code. It should be the same as the follows:

Example 1

Hello World!

3. Variables, Strings and Data Types

(a) Create a file called variable.php in the public_html directory using the following content:

Example 2

(b) Test the file in your Web browser.

(c) A variable is defined by a proceeding $ sign in PHP. Unlike C++ or Java, we do not need to declare a variable in PHP.

Note how strings are represented in PHP. They can be enclosed by either single quote marks (') or double quote marks ("). The semantics of the two representations are different. In single quote marks ('), a string is interpreted as is. When double quote marks (") are used, if there are variables embedded in the string, the values of the variables will replace the variables in the string.

In PHP, values can be strings, integers and floating point numbers.

Now consider the following PHP code segment:

Write down the values of variables y and z.

Answer:

4. For Loop

(a) Create a file called forloop.php in the public_html directory using the following content:

Example of For Loop

The code creates a 4(2 table.

(b) Test the file in your Web browser.

(c) The for-loop syntax of PHP is almost the same as that of C++. Pay special attention to how the PHP code puts a table together. Compare the PHP code with the source code in your Web browser (Menu: View → Source Code).

5. While Loop

Write a PHP script using while-loop to draw a 4(2 table the same way as the for-loop example. The syntax of a while-loop is as follows.

while (condition) {

// loop body;

}

Name your PHP code as whileloop.php. Test your code in your account.

Submit the code along with this lab assignment through email.

6. PHP also provides other control structures such as the if-statement. You can also define arrays and functions in PHP. We will see more in other examples later.

References:

Official PHP Website:

(a)

(b) A list of all PHP functions:

Tutorial:

(a)

(b) A hardcopy of the tutorial (PDF format) is available in D2L.

To prepare for the course project, you need to read the whole tutorial carefully and try examples outside the lab.

7. Insertion in Oracle Tables using PHP

Starting from this step, we discuss the use of PHP for Oracle. We will learn a database concept called cursor. A cursor contains a set of tuples as the result of a query statement (select). The tuples in a cursor can be accessed one at a time. You may consider a cursor as a pointer that goes through the query result one by one sequentially.

(a) Run the following SQL statement in SQL*Plus to check the current content of the table faculty.

select * from faculty;

(b) Create a file called orainsert.php using the following content in directory public_html. Note that you need to replace the account test/test with your own Oracle username and password

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery