<?php class mysql{private $host; Private $name; Private $pass; Private $table; Private $ut; function __construct ($host, $name, $pass, $table, $ut) {$this->host= $host; $this->name= $name; $this->pass= $pass; $this->table= $table; $this->ut= $ut; $this->connect (); } function Connect () {$link =mysql_connect ($this->host, $this->name, $this->pass) or Die ($this->error () ); mysql_select_db ($this->table, $link) or Die ("No database". $this->table); mysql_query ("SET NAMES ' $this->ut '"); }function query ($sql, $type = ") {if (!) ( $query = mysql_query ($sql)) $this->show (' Say: ', $sql); return $query;} Function Show ($message = ', $sql = ') {if (! $sql) echo $message; else echo $message. ' <br> '. $sql;} function Affected_rows () {return mysql_affected_rows ();} function result ($query, $row) {return mysql_result ($query, $row);} function Num_rows ($query) {return @mysql_num_rows ($query);} Function Num_fields ($query) {return mysql_num_fields ($query);} function Free_result ($query) {return mysql_free_result ($query);} function insert_id () {return mysql_insert_id ();} function Fetch_row ($query) {return mysql_fetch_row ($query);} Function version () {return mysql_get_server_info ();} function Close () {return mysql_close ();} ============== function Fn_insert ($table, $name, $value) {$this->query ("INSERT into $table ($name) value ($value) "); }} $db = new MySQL (' localhost ', ' root ', ' ', ' data ', ' GBK '); >
PHP packaged MySQL Operation class