Simple class PHP and MySQL

Source: Internet
Author: User
Tags php and mysql


<?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

Related Article

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.