PDO Knowledge Points Summary

Source: Internet
Author: User
Tags modifiers

Object-oriented: object is first translated into material abbreviation OOP

A constructor is a method that is automatically called when an object is created, and is used to complete the work of class initialization

Constructors can accept parameters and be able to assign values to object properties when creating an object
Constructors can call class methods or other functions
Constructors can call constructors of other classes

Construction method
In object-oriented, a function is called a method
1 Special Name: __construct 2 is automatically invoked when instantiating an object
3 partition the corresponding memory space in memory area 4 The constructor method can receive parameters like normal methods, and the parameters here are usually used to initialize the properties in the class.
5 construction methods cannot be defined repeatedly, and there can be only one in each class; If you do not write an empty function that has a default without parameters and does not have any execution

Destructors execute when an object becomes garbage or when an object is displayed for destruction

Destructors are calls that are automatically called when an object is destroyed and cannot be displayed.
Destructors cannot take parameters.
__destruct () destructor
1 acting in contrast to a constructor, it is used to destroy an object, and he also uses it for simultaneous destruction of associated data.
2 Also, destructors are automatically called
3 destructors cannot pass parameters

Function and Range

Public: The publicly available access level is exposed to members with the Public keyword adornments, that is, exposed members can be accessed by any other object.

Private access level uses the Private keyword adornment, which is the lowest-level private member of the modifier, and only the class itself can access the non-public
Protected: Protected access levels use the protected keyword to decorate a protected member that can be accessed by a class in the same package and accessed by subclasses of the class regardless of which package the subclass is in

GC (garbage collector) garbage disposal mechanism to prevent memory overflow

OOA oriented to the analysis of Ood oriented design OOP oriented programming

Three characteristics of object-oriented: encapsulation inheritance polymorphism

Package Advantages: Information concealment, encapsulation is hidden

Inheritance: Extends the contents of the parent class, noting that only public and protected-decorated content can be inherited, whereas private adornments cannot inherit
Keyword: extends
Inheritance in PHP is a single inheritance, that is, there can be only 1 class names behind extends, but 1 classes may have countless subclasses
Subclasses and parent classes can only be present between 2 classes that have an inheritance relationship
Inheritance is a subclass, inherited is a parent class

Parent::(domain modifier) refers to a function method that calls the parent class
Retroactive not directly to the parent class

Rewrite: A method that appears in a subclass with the same name as the father, this is called rewriting
A redefined override of a behavior can only occur between classes that have an inheritance relationship, which is overridden by the same method name, and does not relate to parameters
When overridden, the access modifier cannot be accessed less than the access modifier in the parent class
The method for private adornments cannot be overridden


Polymorphic: Refers to the ability to redefine or change the nature and behavior of a class in object-oriented contexts based on the context in which the class is used.
Also become abnormal: "The shape of transformation"

Interface: (interface) is a collection of abstract methods and static constants defined as a special class
An interface is a special kind of abstract class that contains only abstract methods and static constants
Interface has no other type of content
The abstract method in the interface can only be public, and the default is public
interface with a plug-in configuration, can be arbitrarily matched to any one of the classes
Class can implement (implements) interfaces, the interfaces implemented by the class can have an infinite number of
When a class implements an interface, all methods of that interface must be implemented in that class

The instanceof operator, which is used for type determination, to determine whether a parameter object belongs to a class


Final keyword, meaning final state, last.
It can modify the function method, the modified function method cannot be rewritten
Final can modify class classes, but the decorated class cannot be inherited
Properties in a class cannot be final decorated

Static statically.
It can modify a property variable, or it can modify a function method
Static resource loading is not the same as normal non-static resource loading
Static methods can be called in non-static methods, but not in the opposite way
Statically static modified content is created without the need for objects to exist, and they are placed in the static zone
The standard way to access static resources is the ===> class name: Static resource Name

An object echo can direct output to prove that it is ToString

PHP Connection Database:

1. Connection 2. Select db/Set character sets 3. Assemble SQL and send 4. Receive and process 5. Close

Mysql_connect () establishing a database connection
mysql_select_db () Select the Operational database
mysql_query () Execute SQL statement
Mysql_fetch_array () returns a row of records (array)
Mysql_num_rows () returns the number of rows in the result set
Mysql_close () Close the database


The PDO itself is a class that queries the function methods and general properties that can be used

Pdo->begintransaction ()-Indicates the rollback start point
Pdo->commit ()-Indicates the rollback end point and executes the SQL
Pdo->__construct ()-Create an instance of the PDO link database
Pdo->errorcode ()-Get error code
Pdo->errorinfo ()-Get the wrong information
Pdo->exec ()-Processes an SQL statement and returns the number of entries affected
Pdo->getattribute ()-Gets a property of a "Database connection object"
Pdo->getavailabledrivers ()-Get a valid PDO drive name
Pdo->lastinsertid ()-Gets the primary key value of the last piece of data written
Pdo->prepare ()-Generates a "Query object"
Pdo->query ()-Processes an SQL statement and returns a "Pdostatement"
Pdo->quote ()-adds quotation marks to a string in a SQL
Pdo->rollback ()-Perform rollback
Pdo->setattribute ()-Set properties for a database connection object


PDO::P Aram_bool
Represents a Boolean type
PDO::P aram_null
Represents a null type in a SQL
PDO::P aram_int
Represents an integer type in sql
PDO::P aram_str
Represents a SQL Char,varchar type in SQL
PDO::P Aram_lob
Represents a large object type in SQL
PDO::P aram_stmt
Represents a recordset type in SQL that has not been supported

Theory: Object-oriented
Concept: a way to recognize or perceive things---"analogy"
object is the result of the instantiation of the class
object=== "Substances, objects
class = = = Property and Behavior
(The category is not determined by default if the attribute or behavior is missing)
Extended add-on behavior----interface
Features: Three major features =====: encapsulation is hidden, hidden by the ability to modify, prevent others to change information at will. means to implement encapsulation: access modifiers, classes, function methods, files, folders
Access modifiers: public, protected, private


inherit = = = "Expand/expand Extends PHP is a single-inheritance rewrite (under what circumstances cannot be overridden)
Final this: the object of the current class/Parent: Parent class object/self: Some methods of invoking the class itself, usually used for static, relative to the

Parent class <====> subclass can see the public and protected of the parent class


Polymorphic: Abstract Interface interface = = = "Realization of Implements

Exception information: @ error_reporting ignore error message Display_errors
Namespaces: Namespace

Introduction file: Include Include_once require require_once


Template engine = = = = smarty3.1 Separation and division of labor
Template folder, template converted folder, plug-in library, configuration file, cache file
TPL delimiter default {} ====> recommended <{}>
<{}>\<{if}>...<{/if}>
<{foreach}>
<{foreachelse}>
<{/foreach}>


Assign ()
Display ()

Code: Class "= = =" Object
PDO = = = "PHP Data Object"
Smarty

PDO class

Pdostatement class

New PDO (' Database connection access string ', ' Login user name ', ' Login password ', ' Access related parameters ')
Mysql:databasename=test;port=3306;host=localhost;charset=utf8


EXEC ($sql) ====>int type
Query ($sql) =====>pdostatement Object
Prepare ($sql) ====>pdostatement Object


Fetch fetches a row of data to return a one-dimensional array
Fetchall returns a two-dimensional array
Fetchobject return Object Format

PDO Knowledge Points Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.