Presentation is loading. Please wait.

Presentation is loading. Please wait.

Server-Side Application and Data Management IT IS 3105 (FALL 2009)

Similar presentations


Presentation on theme: "Server-Side Application and Data Management IT IS 3105 (FALL 2009)"— Presentation transcript:

1 Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Object-Oriented PHP Mohamed Shehab Lecture 4

2 Classes and Objects An object can be almost any item or concept,
a physical object such as a desk or a customer, or a conceptual object in software such as a text input area or a file. Objects have both attributes and operations Attributes are properties or variables that relate to the object Operations are methods, actions , or functions that the object can perform

3 Classes and Objects Objects can be grouped into classes
Classes represent a set of objects that vary from individual to individual A class contains objects that all have the same operations behaving in the same way and the same attributes representing the same things, although the values of those attributes vary from object to object.

4 Creating Classes class classname{ public $attribute1; public $attribute2; function operation1($param1, $param2){ }

5 Constructors A constructor is called when an object is created, it normally performs useful initialization tasks such as Setting attributes to sensible starting values Creating other objects needed by this object class classname{ function __construct($param1, $param2){ }

6 Instantiating Classes
class classname{ function _construct($param){ echo "Constructor called with parameter". $param."<br />"; } } $a = new classname("First"); $b = new classname("Second"); $c = new classname();

7 Using the Class Attributes
Inside the class: class classname{ public $attribute; function operation($param){ $this->attribute = $param; echo $this->attribute; }

8 Using the Class Attributes
From outside the class: class classname{ public $attribute; } $a = new classname(); $a->attribute = "value"; echo $a->attribute;

9 Introduction to Relational Databases

10 Database Overview A database provides a means to organize and retrieve data. The database is the set of physical files in which all the objects and database metadata are stored. These files can usually be seen at the operating system level.

11 Database overview Different types of Database structures (Hierarchical, Relational, Temporal) are based on the way they store the data on Hard Disk Drive and how they read from the stored data. Famous Relational Databases: Oracle, MS SQL (Microsoft), DB2 (IBM), MySQL, mSQL, Postgre SQL and etc. MySQL is an open source relational database management system (RDBMS) that uses Structured Query Language (SQL), the most popular language for adding, accessing, and processing data in a database.

12 Database Introduction
RDBMS (Relational Database Management System) RDBMSs can provide faster access to data than flat files. RDBMSs can be easily queried (SQL Language) to extract sets of data that fit certain criteria. RDBMSs have built-in mechanisms for dealing with concurrent access so that you as a programmer don't have to worry about it. RDBMSs have built-in privilege systems.

13 SQL SQL: “Structured Query Language”—the most common standardized language used to access databases. SQL has several parts: DDL – Data Definition Language {Defining, Deleting, Modifying relation schemas} DML – Data Manipulation Language {Inserting, Deleting, Modifying tuples in database} Embedded SQL – defines how SQL statements can be used with general-purposed programming

14 Basic Definitions Table, a set of columns that contain data. In the old days, a table was called a file. Row, a set of columns from a table reflecting a record. Index, an object that allows for fast retrieval of table rows. Every primary key and foreign key should have an index for retrieval speed. Primary key, often designated pk, is 1 or more columns in a table that uniquely identify a record.

15 Basic Definitions Relational databases are made up of relations, more commonly called tables. A table is exactly what it sounds like a table of data. If you've used an electronic spreadsheet (Excel), you've already used a relational table. A database usually consists of several tables. MySQL can handle thousands of databases. Table Database

16 Basic Definitions number name department salary location Kerwin 413
2000 New Jersey 34589 Larson 642 1800 Los Angeles 35761 Myers 611 1400 Orlando 47132 Neumann 9000 78321 Stephens 8500 Row Column Primary key number name department salary location 23603 Jones 413 1100 New Jersey 24568

17 Basic Definitions Elements of the relational database table: Table
Key (auto-increase) Attribute Column Row (Topple) Foreign Key (referring to another table) Cell

18 Basic Definitions Foreign key, often designated fk, is a common column common between 2 tables that define the relationship between those 2 tables. Foreign keys are either mandatory or optional. Mandatory forces a child to have a parent by creating a not null column at the child. Optional allows a child to exist without a parent, allowing a nullable column at the child table (not a common circumstance).

19 Foreign Key (referring to another table)
Basic Definitions Foreign Key (1 to Many): Foreign Key (referring to another table) Table: Patient_information (MANY) Table: City_information (ONE)

20 Basic Definitions Foreign Key (Many to Many):
Patient #1 has doctor #4, #5 and #6. Dr. #1 has patient #2 and #4. Table: Doctor_information (MANY) Table: Patient_information (MANY) Table: Patient_Doctor_realationship

21 Create a Database An SQL relation is defined using the CREATE DATABASE command: create database [database name] Showing what are the available databases, use the show command: show databases; Using a specific database: use [database name]

22 Create Table An SQL relation is defined using the CREATE TABLE command: Create table [tablename] (A1 T1,A2 T2, … An Tn, (integrity-constraint1), …, (integrity-constraintk)) Each Ai is an attribute name in the table Each Ti is the data type of values for Ai Example Create table student (SID char(9) not null, name varchar(30), age integer, department varchar(20), primary key (SID) );

23 Insert into a Table Add a new tuple to a table:
insert into table name values(V1, V2, V2);


Download ppt "Server-Side Application and Data Management IT IS 3105 (FALL 2009)"

Similar presentations


Ads by Google