PHP Introduction - File Structures and Database Systems | CPSC 332, Exams of Computer Science

Material Type: Exam; Professor: Wang; Class: File Structures and Database Systems; Subject: Computer Science; University: California State University - Fullerton; Term: Unknown 1989;

Typology: Exams

Pre 2010

Uploaded on 08/18/2009

koofers-user-k0a
koofers-user-k0a 🇺🇸

4.5

(1)

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PHP Introduction
Dr. Xiong Wang
Department of Computer Science
Cal State Fullerton
A simple PHP example
<html>
<head>
<title>First PHP Example< /title>
</head>
<body>
<?php echo "<p><h1>Outp ut</h1>";
echo "<h2>Output</h2>";
echo "<h3>Output</h3></p >";
?>
<script language="PHP">
echo "\n<b>More PHP Output< /b><br />\n";
</script>
</body>
</html>
------------------------ -------------------- --------------------
<html>
<head>
<title>First PHP Example< /title>
</head>
<body>
<p><h1>Output</h1><h2>O utput</h2><h3>Output </h3></p>
<b>More PHP Output</b><b r />
</body>
</html>
Using MySQL database
Connect with MySQL RDBMS
$link=mysql_connect($hostName,
$userName, $password) or die("Unable to
connect to host $hostName");
Connect with database
mysql_select_db($dbName, $link) or
die("Unable to select database $dbName");
pf3
pf4

Partial preview of the text

Download PHP Introduction - File Structures and Database Systems | CPSC 332 and more Exams Computer Science in PDF only on Docsity!

PHP Introduction

Dr. Xiong Wang

Department of Computer Science

Cal State Fullerton

A simple PHP example

**

First PHP Example

Output"; echo "Output"; echo "Output

"; ?>

**

**----------------------------------------------------------------

First PHP Example

OutputOutputOutput

More PHP Output

**

Using MySQL database

„ Connect with MySQL RDBMS

„ $link=mysql_connect($hostName,

$userName, $password) or die("Unable to

connect to host $hostName");

„ Connect with database

„ mysql_select_db($dbName, $link) or

die("Unable to select database $dbName");

Executing SQL

„ Basic information searches

„ $SQL = "SELECT FirstName, LastName, DOB,

Gender FROM Patients WHERE Gender = '$Gender‘

ORDER BY FirstName DESC";

$Patients = mysql_query($SQL, $link);

„ Editing, adding, and deleting records and tables

„ $SQL = "INSERT INTO Patients (FirstName,

LastName) VALUES('$firstName', '$lastName')";

$Patients = mysql_query($SQL $link);

Closing the Connection

„ Cleaning up: close the database connection

„ mysql_close($link);

PHP data types

boolean

TRUE or FALSE

integer

Platform dependent – size of one machine word 32

bits on most machines

float

Double precision. We could call it a double, but

since we don't declare variables (we will discuss

shortly) float works

PHP Expressions and Operators

„ Similar to those in C / C++

„ Be careful with a few operators

„ / in PHP is always floating point division ƒ To get integer division, we must cast to int $x = 15; $y = 6; echo ($x/$y), (int) ($x/$y), ""; ƒ Output is 2.5 2 „ Inequality operators do not compare strings ƒ Will cast strings into numbers before comparing ƒ To compare strings, use the C-like string comparison function, strcmp()

PHP Control Structures

„ Again, these are similar to those in C++

„ if , while , do , for , switch are virtually identical

to those in C++

„ PHP allows for an alternative syntax to designate

a block in the if, while, for and switch statements

ƒ Open the block with : rather than {

ƒ Close the block with endif, endwhile, endfor, endswitch ƒ Advantage to this syntax is readability ƒ Now instead of seeing a number of close braces, we see different keywords to close different types of control structures

Creating Arrays

„ PHP Arrays can be created in a number of

ways

„ Explicitly using the array() construct

„ Implicitly by indexing a variable

ƒ Unlike Perl, arrays in PHP do not have a different prefix for the variable name. Thus you cannot have a scalar and an array with the same variable name at the same time ƒ However, you can test a variable to see if it is an array or not ƒ is_array() returns true or false

„ Size will increase dynamically as needed