写的比较简单 可以完成连接数据库和插入的操作,如果需要还可以继续完善
<?php
class mysql {
private $host;
private $name;
private $pass;
private $db_name;
function __construct($host, $name, $pass, $db_name) { // 初始化
$this->host = $host;
$this->name = $name;
$this->pass = $pass;
$this->db_name = $db_name;
$this->connect ();
}
function connect() { // 连接
$link = @mysql_connect ( $this->host, $this->name, $this->pass ) or die ( mysql_error () ); // 连接mysql
mysql_select_db ( $this->db_name, $link ) or die ( "没有该数据库:" . $this->db_name ); // 连接数据库
mysql_query ( "SET NAMES 'GB2312'" );
}
function mysql_insert($table, $value) {//插入
return mysql_query ( "insert into $table values ($value)" ) or die ( mysql_error () );
}
}
// $p=new mysql('localhost','root','123456','test');
// $p->mysql_insert('user', '24,"来来来",2222');
?>