1 / 16

PHP and MySQL

PHP and MySQL . Code Reuse, OO, Error Handling and MySQL (Intro). r equire() 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 )

karli
Download Presentation

PHP and MySQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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.htmlvshome.php) • require(‘<filename>’) • include(‘<filename>’)

  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.html

  12. MySQL - Creating tables • Logon to cisc474.acad.cis.udel.edu mysql –u <username> -p • You will be prompted for your password • To open your db type use <username> • To create a table • http://dev.mysql.com/doc/refman/5.1/en/create-table.html • bookorama.sql

  13. MySQL Create tables • To run a sql script source <filename> • Look up table info with SHOW and DESCRIBE • Get up to speed with INDEX • http://dev.mysql.com/doc/refman/5.1/en/create-index.html • MySQL datatypes • http://dev.mysql.com/doc/refman/5.1/en/data-type-overview.html

  14. Working with MySQL Data • Insert • Select • Cartesian product (aka Full Join, Cross Join) • Inner join • Equi-join • Outer Join (Left, Right) • Update • Alter • Delete

  15. MySQL and PHP • Now that you have mastered the basics of MySQL… • How do you put PHP and MySQL together… • It is quite simple! • Search and newbook examples!

  16. Building eCommerce Sites • What makes a site fail?

More Related