www.gusucode.com > TD-Love CMS系统源码程序 > libs/mysql.php
<?php /** * @author :康云川 webSite:www.kangyunchuan.cn Qq:334192009 */ define(ROOT,$_SERVER['DOCUMENT_ROOT']); require_once(ROOT."/libs/SMARTY/Smarty.class.php"); $smarty = new Smarty(); $smarty->template_dir = ROOT.'/application/index/views/'; $smarty->compile_dir = ROOT.'/templates_c'; $smarty->left_delimiter="<!--{"; $smarty->right_delimiter="}-->"; $smarty->cache_lifetime = 1800; class Mysql{ private $host = "localhost";//数据库主机地址 private $userName = "root";//数据库用户名 private $passWord = "123456";//数据库用户密码 private $dbName = "cms";//数据库名 public $tableName;//数据表名 private $charset = "set names utf8";//设置字符集编码 public $limit;//设定显示的记录数 public $where;//筛选数据 public $showArray;//记录显示以数组返回 public $name;//字段名称 public $value;//字段名称对应的值 记住值加单引号 public $update;//更新数据 记住值加单引号 public $total;//数据记录的总数 private $connect;//数据库连接 public $order; public function __construct(){ $this->connect = $operation = @mysql_connect($this->host,$this->userName,$this->passWord); $operation1 = @mysql_select_db($this->dbName); @mysql_query($this->charset); date_default_timezone_set(PRC); //更正时间为中国时间 if (!$operation) { throw new Exception("数据库连接失败"); } elseif (!$operation1) { throw new Exception("没有数据据库:".$this->dbName); } } public function show(){ $queryString = "select * from `$this->tableName` $this->where $this->order $this->limit "; $ro = mysql_query($queryString); if (!$ro) { throw new Exception("没有数据表"); //echo mysql_error(); } return $this->ro = $ro; } public function insert(){ $queryString = "insert into `$this->tableName`($this->name) values ($this->value)"; $operation = mysql_query($queryString); if (!$operation) { throw new Exception("数据插入失败"); //echo mysql_error(); } } public function delete(){ $queryString = "delete from `$this->tableName` $this->where"; $operation = mysql_query($queryString); if (!$operation) { throw new Exception("数据删除失败"); } } public function update(){ $queryString = "update `$this->tableName` set $this->update $this->where "; $operation = mysql_query($queryString); if (!$operation) { throw new Exception("数据更新失败"); } } public function total(){ $queryString = "select * from `$this->tableName` $this->where"; $ro = mysql_query($queryString); $this->total = mysql_num_rows($ro); return $this->total; } public function __destruct(){ @mysql_close($this->connect); } } ?>