In object-oriented programming (English: object-oriented programming, abbreviation: OOP), an object is a whole that consists of information and a description of the information being processed, and is an abstraction of the real world.
In the real world we are confronted with objects such as computers, televisions, bicycles, etc.
The main three properties of the object are:
Object behavior: You can apply those actions to objects, turn on the lights, turn off the lights is the behavior.
The shape of the object: When applying those methods is how the object responds, color, size, shape.
Object representation: The representation of an object is equivalent to an identity card, specifically distinguishing between the same behavior and the state of what is different.
For example, Animal (animal) is an abstract class, we can be specific to a dog and a sheep, and dogs and sheep is the specific object, they have color attributes, can write, can run and other behavior state.
This article mainly introduces the PHP object-oriented transaction script pattern
/* Transaction script mode: Similar to the model layer in thinkphp, or the class that operates the database. Personally feel that the use of practice is quite simple and convenient, that is, the SQL statement written dead, flexibility is not enough. The sample code is as follows: */namespace woo\process;abstract class base{static $DB; PDO object Static $stmts = Array (); SQL statement handle function construct () {$DSN = \woo\base\applicationregistry::getdsn (); if (Is_null ($DSN)) {throw new \woo\base\appexception ("No DSN"); } self:: $DB = new PDO ($DSN); Self:: $DB->setattribute (\pdo::attr_errmode,\pdo::errmode_exception); } function Preparestatement ($stmt _s) {//cache SQL statement handle if (Isset (self:: $stmts ($stmt _s)) {Return to self:: $stmts [$stmt _s ]; } $stmt _handle = self:: $DB->prepare ($stmt _s); Self:: $stmts [$stmt _s] = $stmt _handle; return $stmt _handle; } protected function Dostatement ($stmt _s, $values _a) {//Execute SQL and get a statement resource $sth = $this->preparestatement ($stmt _s); $sth->closecursor (); $db _result = $sth->execute ($values _a); return $sth; }}//This class is to write some data to the database, relatively simple not much to say the class Venuemanager extends base{static $add _venue = INSERT into venue (name) values (?); static $add _space = "INSERT into space (name,venue) VALUES (?,?)"; static $check _slot = "Select Id,name from event WHERE space =?" and (start+duration); and start <? "; static $add _event = "INSERT into event (name,space,start,duration) VALUES (?,?,?,?)"; function Addvenue ($name, $space _array) {$ret = array (); $ret [' venue '] = array ($name); $this->dostatement (self:: $add _venue, $ret [' venue ']); $v _id = self:: $DB->lastinsertid (); $ret [' spaces '] = array (); foreach ($space _array as $space _name) {$values = array ($space _name, $v _id); $this->dostatement (self:: $add _space, $values); $s _id = self:: $DB->lastinsertid (); Array_unshift ($values, $s _id); $ret [' spaces '] [] = $values; } return $ret; } function Bookevent ($space _id, $name, $time, $duration) {$values = array ($space _id, $time, ($time + $duration)); $stmt = $this->dostatement (self:: $check _slot, $values, false); if ($result = $stmt->fEtch ()) {throw new \woo\base\appexception ("Double booked! Try again "); } $this->dostatement (self:: $add _event,array ($name, $space _id, $time, $duration)); }}//client, it is relatively easy to use $venue = new Venuemanager (), $venue->addvenue (' Test ', Array (' test1 ', ' test2 ', ' test3 ');