<?php
Header ("content-type:text/html; Charset=utf-8 ");
/*__construct () initialization
*php+mysql class
*/
Class mysql{
Private $host;
Private $name;
Private $pass;
private $table;//database table
Private $ut;
initialization function
function __construct ($host, $name, $pass, $table, $ut) {
$this->host = $host;
$this->name = $name;
$this->pass = $pass;
$this->table = $table;
$this->ut = $ut;
$this->connect ();
}
To establish a function to connect to a database
function Connect () {
Mysql_connect ($this->host, $this->name, $this->pass) or Die (Mysql_error ());
$link = mysql_connect ($this->host, $this->name, $this->pass) or Die (Mysql_error ());
echo "Connected successfully";
mysql_select_db ($this->table, $link) or Die ("No database". $this->table);
mysql_query ("SET NAMES". $this->ut);//This insertion is garbled. Because the encoding format is quoted
mysql_query ("SET NAMES ' $this->ut '");
}
Execute MySQL statement function
function query ($v) {
return mysql_query ($v);
}
Encapsulation error message
function Errora () {
return Mysql_error ();
}
//====================
function Fn_insert ($table, $name, $value) {
Table name, field name, field value
$this->query ("INSERT into $table ($name) value ($value)");
}
}
$db = new MySQL ("localhost", "root", "" "," laok "," UTF8 ");
$db->fn_insert (' Test ', ' id,uid,regdate,remark ', ' ', ' I inserted the information at ', ' Now (), ' ");
?>
Simple class PHP and MySQL