php一个mysql操作CRUD类
代码如下
<?php
class ConnectionMySQL{
public $host="localhost";
public $name="root";
public $pass="wangqi";
public $database="myweb";
function __construct(){
$this->connect();
}
function connect(){
$link=mysql_connect($this->host,$this->name,$this->pass) or die ($this->error());
mysql_select_db($this->database,$link) or die("没该数据库:".$this->database);
mysql_set_charset('utf8',$link);
}
function mysql_query($sql, $type = '') {
if(!($query = mysql_query($sql)))
{
$this->show('error:', $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 column_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 mysql_insert($table,$name,$value){
$insert = $this->mysql_query("insert into $table ($name) value ($value)");
return $insert;
}
function mysql_delete($table,$column,$value){
$delete = $this->mysql_query("delete from $table where $column='$value'");
return $delete;
}
function mysql_exists($table, $ip, $value)
{
$count = $this->mysql_query("select count(*) from $table where $ip = '$value'");
return $count;
}
function mysql_update($table, $column, $value)
{
$update = $this->mysql_query("update set $table set $column = '$value'");
return $update;
}
function mysql_getdata($query)
{
return mysql_fetch_assoc($query);
}
}
?>