Title: Accelerating PHP development
1Accelerating PHP development
- Data-tier programming
- Brian Rosenthal
- Zvi Boshernitzan
- Robocommerce
2Overview Data modeling
- High-level approach to database design.
- We will describe
- Basic principles of data modeling
- PHP Programming techniques
- Database abstractions
- Stack-based database programming
- Inference-based database programming
3Basic principles of data modeling
- Normalization Dont repeat yourself.
- Entity Relation ER diagrams
4NormalizationDont Repeat Yourself
- First approach store the author information
within the book. - Problem what if there is more than one author.
Where do we store the second author?
5NormalizationDont Repeat Yourself
- Second approach store up to three authors
- Problems what if there are more, and what about
all of the information about the authors
(address, etc.)
6NormalizationDont Repeat Yourself
- Third approach have two tables books and
authors. - Authors have a book id.
- Each book may be written by 0 or more authors.
- Each author must be the writer of a book.
7NormalizationDont Repeat Yourself
- Problem We still have redundancy
8NormalizationDont Repeat Yourself
- Fourth approach have three tables books,
people, authorship. - Each entry in the authorship table is a fact.
That a particular person participated in an
authorship of a book - No information is repeated!
9ER Diagrams
- This is an ER diagram.
- You read it Each product must be sold under a
brand - Each brand may be the origin of 0 or more
products
10PHP Database Infrastructure
- Zvi database abstractions.
- Brian stack-based SQL programming
- Brian inference-based SQL programming
11Database stack programming
- SQL as a big string versus SQL as a stack
- SQL is, after all structured.
- selectfirstname,lastname
- , fromcustomers c
- , ijoinstablesites, ons.id
c.site_id - , wherec.name like brian, c.id gt 10
- , limit10
- , offset5
-
- q-gtadd_where()
- q-gtadd_select(), q-gtset_select()
- q-gtadd_lojoin()
- q-gtload_dict(selectc.address_id,
where) - q-gtto_sql()
- q-gtto_dict()
12SPEC DRIVEN DATABASE PROGRAMMING
- dbobjects(q-gtto_sql())
- dbassocs(q-gtto_sql())
- dbstring(q-gtto_sql())
- dbobject(q-gtto_sql())
13INFERENCE-BASED DATABASE PROGRAMMING
- A lot of information is stored in the database
schema - The idea here is to use it where it is possible
to do so
14Inferences from ER diagrams if you were writing
classes to manage these database entities, you
might include
- productsmget_by_category()
- productsmget_by_brand()
- productsmap_keyword()
- productsmget_by_keyword()
- keywordsmget_by_product()
15Enter PHP 5
- Call handler override
- function __call(m, args)
- Mysql reflection
- Singleton / factory semantics
- Autoloads
16- You should really get all of these functions for
free - mg(products)-gtget(product_id)
- mg(products)-gtcreate(name, lawnmower)
- mg(products)-gtmget_by_keyword(keyword_id)
- mg(products)-gtmget_by_category(category_id)
- mg(products)-gtmget_by_brand(brand_id)
- mg(products)-gtget_by_sku(sku)
- mg(products)-gtget_title(product_id)
- mg(products)-gtget_title(sku, sku)
- mg(products)-gtmap_keyword(keyword_id)
- mg(products)-gtcolnames()
- mg(categories)-gtget_products(category_id)
17- So, heres the class
- class products extends dbentity
- function references()
- return array('brand_id' gt 'brands,
'category_id' gt 'categories') -
- function mappings()
- return array(
- keywords' gt array(product_keywords',
'product_id', keyword_id', keywords) - , related_products' gt array('product_relations
', 'from_product_id', 'to_product_id',
'products') - , 'suppliers' gt array('supplier_prices',
'product_id', 'supplier_id', 'suppliers - , array('wholesale_price' gt 'price', 'sku'
gt 'sku')) - )
-
18- Customizing the sql
- q new dbquery(array(
- select gt p.name
- , from gt products p
- , ijoin gt array(c gt rba_(table,
categories - , on, c.id p.category_id))
- , where gt name like lemon
- , order_by gt p.name
- ))
- q-gtadd_select(p.subname)
- q-gtadd_ijoin()
- q-gtset_limit()
- q-gtload(q_spec)
19- Customizing the SQL
- dbquery array(
- select gt c.name as category_name
- , ijoin gt array(c gt rba_(table,
categories - , on, c.id p.category_id)))
- mg(products)-gtget(product_id,
compact(dbquery))
20Zachman Framework
Data(What)
Activities(How)
People(Who)
Timing(When)
Motiva-tion (Why)
Network(Where)
List of Important Things
Organi- zational Units
Business Events, Cycles
Objectives/ Scope
List of Processes
Business Locations
Business Vision and Mission
Business Process Model
Operationsby Business Location
Org. Chart, Roles
Master Business Schedule
Business Policies and Rules
Business Owners View
Terms, Definitions
Entity/ Relationship Diagram
Data Links, Processing Locations
RolesData (Use Cases)
State/ transactions, ELH
Essential Functions
Business Rule Model
Architects View
Network Architecture (h/w, s/w types)
User Interface, Security
Control Flow diagrams
Designers View
Tables, Classes
System Design
Rule Design
Data, physical storage design
Detailed Program Design
Screens, Security Design
Network Construction
Timing Definitions
Rule Specification
Builders View
Functioning System
Working System