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