|
项目结构:

运行效果;

conn.php
[U]复制代码[/U] 代码如下:
ut=$ut;
$this->connect();
}
//数据库的链接
function connect(){
$link=mysql_connect($this->host,$this->name,$this->pass) or die ($this->error());
mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);
mysql_query("SET NAMES '$this->ut'");
}
function query($sql, $type = '') {
if(!($query = mysql_query($sql))) $this->show('Say:', $sql);
return $query;
}
function show($message = '', $sql = '') {
if(!$sql) echo $message;
else echo $message.'
'.$sql;
}
function affected_rows() {
return mysql_affected_rows();
}
function result($query, $row) {
return mysql_result($query, $row);
}
function 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();
}
//向$table表中插入值
function fn_insert($table,$name,$value){
$this->query("insert into $table ($name) value ($value)");
}
//根据$id值删除表$table中的一条记录
function fn_delete($table,$id,$value){
$this->query("delete from $table where $id=$value");
echo "id为". $id." 的记录被成功删除!";
}
}
$db = new ConnectionMySQL();
$db->fn_insert('test','id,name,sex',"'','hongtenzone','M'");
$db->fn_delete('test', 'id', 1);
?>
您可能感兴趣的文章:php连接mysql数据库代码memcached 和 mysql 主从环境下php开发代码详解php开启mysqli扩展之后如何连接数据库PHP连接局域网MYSQL数据库的简单实例PHP同时连接多个mysql数据库示例代码php基础之连接mysql数据库和查询数据Php连接及读取和写入mysql数据库的常用代码PHP使用mysqli扩展连接MySQL数据库PHP连接和操作MySQL数据库基础教程Yii 连接、修改 MySQL 数据库及phpunit 测试连接php监测数据是否成功插入到Mysql数据库的方法PHP实现的mysql主从数据库状态检测功能示例
|
|