Simple PHP MySQL class (query delete update)

Source: Internet
Author: User
Tags php mysql
The code is as follows Copy Code
Class MySQL
{
Private $host;
Private $user;
Private $pass;
Private $database;
Private $charset;
function __construct ($host, $user, $pass, $database, $charset)
{
$this--->host= $host;
$this->user= $user;
$this->pass= $pass;
$this->database= $database;
$this->charset= $charset;
$this->connect ();
}
Private function connect ()//Join functions
{
Mysql_connect ($this->host, $this->user, $this->pass) or Die ("failed to connect to database server!");
mysql_select_db ($this->database) or Die ("failed to connect to database!");
mysql_query ("Set names $this->charset");
}
function Select ($sql, $tab, $col, $value)//select functions
{
$select =mysql_query ("Select $sql from $tab where $col = $value");
$row =mysql_fetch_array ($select);
return $row;
}
function inserts ($tab, $col, $value)//Insert Data functions
{
mysql_query ("INSERT into $tab ($col) VALUES ($value)");
}
function Update ($tab, $col, $new _value, $colm, $value)//Updating data functions
{
mysql_query ("UPDATE $tab SET $col = $new _value where $colm = $value");
}
function Delete ($tab, $col, $value)//Remove Data functions
{
mysql_query ("DELETE from $tab where $col = $value");
}
function close ()//Turn off join functions
{
Mysql_close ();

}
}
$mysql =new MySQL ("127.0.0.1", "root", "120360150", "Test", "GBK");
$sql = $mysql->select ("*", "admin", "id", "3");//Select data
Print_r ($sql);//print returned array
$mysql->insert ("admin", "User_name,user_pass", "' 123", ' 123 "); Insert data
$mysql->update ("admin", "User_pass", "All", "id", "3"); Update data
$mysql->delete ("admin", "id", "4"); Delete data
$mysql->close (); Close connection
?>
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.