Easy to understand
Image "Like two people fight, you have to use the program to describe it, oriented structure, you are each step of the rally are written, such as what the other side out what tricks, you have to write every step, the object-oriented approach, you want to break the fight process into several parts, fight before, fight, and later."
Now for the PHP object-oriented approach, has been learning for some time, the system has been done in the object-oriented approach.
Say the object-oriented benefits, it can make the system very good modularity, can let a lot of programmers work together, improve the efficiency of coding. For the whole system maintenance and update is also convenient a lot of.
Below post a class out, everybody feels about it. This is the base class for database links and operations, and it is a reference for other classes.
/*
Database class files: class_database.php
Database operations classes, this class is the basis for other classes of operations, that is, the implementation of other class functions generally through the database class implementation
Created in the world: May 17, 2007
*/
Include_once ("Config.inc"); Contains system configuration files
Class Data_class
{
Property
Private $host; Server name
Private $user; User name
Private $pwd; Password
Private $name; Database name
Private $connection; Connection identification
Method
__get (): Get property value
function __get ($property _name) {
if (Isset ($this-$property _name))
{
Return ($this, $property _name);
} else {
return (NULL);
}
}
__set (): Sets a single private data property value for a small amount of modification data
function __set ($property _name, $value)
{
$this $property _name = $value;
}
__construct: constructors, establishing a connection, automatically called when a function is established, and not explicitly called when new objects are created
function __construct ()
{
$this->host=sys_conf:: $dbhost; Using static properties of the Sys_conf class
$this->user=sys_conf:: $dbuser;
$this->pwd=sys_conf:: $dbpswd;
$this->name=sys_conf:: $dbname;
Establish a connection to the database
$this->connection=mysql_connect ($this->host, $this->user, $this->pwd);//Establish connection
mysql_query ("Set names UTF8");//Unity of the character set
mysql_select_db ("$this->name", $this->connection); Select Database Challenge Cup
}
__destruct: Destructors, disconnects, and automatically invokes a destructor when the function is finished executing. Implement a connection to close the database to ensure that the data
Security of library data
function __destruct ()
{
Mysql_close ($this->connection);
}
Additions and Deletions: parameter $sql to insert update
function Execute ($sql)
{
mysql_query ($sql);
echo "Writing to the database was successful";
echo "I am the Execute function of the DataClass class";
}//execute
Check: Parameter $sql is INSERT statement
The return value is an array of objects, and each element in the array is an object of one row of records
function query ($sql)
{
$result _array=array (); Returns an array
$i = 0; Array subscript
$query _result= @mysql_query ($sql, $this->connection); Querying data
while ($row = @mysql_fetch_object ($query _result))
{
$result _array[$i]= $row;
}//while
return $result _array;
}
Number of record functions for obtaining query results
function Result_query ($sql)
{
$result =mysql_query ($sql);
$result _c=mysql_num_rows ($result);
return $result _c;
}
}
?>
http://www.bkjia.com/PHPjc/486230.html www.bkjia.com true http://www.bkjia.com/PHPjc/486230.html techarticle simple understanding of the image "like two people fight, you have to use the program to describe it, oriented structure, you are each step of the rally are written, such as the other side out what tricks, you out what recruit ... "