Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP and MySQL Code Reuse, OO, Error Handling and MySQL (Intro)

Similar presentations


Presentation on theme: "PHP and MySQL Code Reuse, OO, Error Handling and MySQL (Intro)"— Presentation transcript:

1 PHP and MySQL Code Reuse, OO, Error Handling and MySQL (Intro)

2 require() and include() Software Engineering tenets tell us to reuse code rather than write new code. – Lower Cost – Increased reliability (in theory!) – Improved consistency Code reuse in PHP (home.html vs home.php) – require(‘ ’) – include(‘ ’)

3 Object-Orientation What is it? – Classes – defines abstract characteristics of a thing State (data) Behavior (procedure/methods) Identity (unique identifier for an instance of the class) – Polymorphism - ability to create a variable, a function, or an object that has more than one form Dog, cat and bird can all “talk” but does so differently. Same function call, different result. Operator overloading – (+, -, * and /) can be performed differently in classes. – Inheritance – create a new class as an extension of an existing class class Student extends Person

4 Object Orientation in PHP home.php and services.php Both use Page class defined in page.inc Very simple to create and rapidly deploy pages with the same look and feel services.php uses inheritance to extend Page class to reuse code and only add code that is unique to that page!

5 Exception Handling Exception handling - mechanism designed to handle the occurrences that change the normal flow of program execution. Basic Concepts – try { //code goes here } – catch{ //handle exception} Back to Bob’s Auto Parts… – Handling file open exceptions…

6 MySQL SQL – Structured Query Language – Based on Relational Algebra Data is structured into: – Databases – a group of related tables – Tables – a container of related Tuples – Tuples – a set of individual values – Keys – a way to uniquely identify tuples

7 MySQL To create tables you need to be familiar with Database Normalization – Gather like data together to form a table – Look to avoid anomalies and wasted space Insertion anomaly Modification anomaly Deletion anomaly – Atomic values – each column stores only 1 instance of a type of information

8 MySQL Choose sensible keys – A key of a last name will limit your customer base! Think about what you want to ask the DB – make sure you capture the info to answer the questions! – What are my top sellers? – Who are my best customers? Avoid designs that create empty column – Books(ISBN, Author, Title, Price, Review)

9 MySQL DB Design Use the KISS rule. – Create tables that mirror real world objects – Avoid anomalies – Keys can be used to link tables together

10 MySQL Accessing your CISC474 MySQL database… – A database has been created for each of you to use. – Username/DB Name: Your ECE/ACAD username OR first initial/last name (John Smith = jsmith). – Password: Your username + last 4 digits of your Student ID… Change it ASAP to something easy to remember but difficult for others to guess… Do not use a password that you would not either the TA or myself to see since you will need to enter it into PHP scripts!

11 MySQL Change password: SET PASSWORD = PASSWORD(‘newpass’); Great source for MySQL (we are using version 5.1) – http://dev.mysql.com/doc/refman/5.1/en/index.h tml http://dev.mysql.com/doc/refman/5.1/en/index.h tml

12 MySQL - Creating tables Logon to cisc474.acad.cis.udel.edu mysql –u -p – You will be prompted for your password To open your mysql db type use


Download ppt "PHP and MySQL Code Reuse, OO, Error Handling and MySQL (Intro)"

Similar presentations


Ads by Google