php 类

 1 <?php
 2     class mysql{
 3 
 4 
 5      private $host;
 6      private $name;
 7      private $pass;
 8      private $table;
 9      private $ut;
10 
11 
12 
13      function __construct($host,$name,$pass,$table,$ut){
14          $this->host=$host;
15          $this->name=$name;
16          $this->pass=$pass;
17          $this->table=$table;
18          $this->ut=$ut;
19          $this->connect();
20 
21      }
22 
23 
24      function connect(){
25       $link=mysql_connect($this->host,$this->name,$this->pass) or die ($this->error());
26       mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);
27       mysql_query("SET NAMES ‘$this->ut‘");
28      }
29      
30 //-------------------------系统方法区------------------------------------
31 
32     function query($sql, $type = ‘‘) {
33         if(!($query = mysql_query($sql))) $this->show(‘Say:‘, $sql);
34         return $query;
35     }
36 
37     function show($message = ‘‘, $sql = ‘‘) {
38         if(!$sql) echo $message;
39         else echo $message.‘<br>‘.$sql;
40     }
41 
42     function affected_rows() {
43         return mysql_affected_rows();
44     }
45 
46     function result($query, $row) {
47         return mysql_result($query, $row);
48     }
49 
50     function num_rows($query) {
51         return @mysql_num_rows($query);
52     }
53 
54     function num_fields($query) {
55         return mysql_num_fields($query);
56     }
57 
58     function free_result($query) {
59         return mysql_free_result($query);
60     }
61 
62     function insert_id() {
63         return mysql_insert_id();
64     }
65 
66     function fetch_row($query) {
67         return mysql_fetch_row($query);
68     }
69 
70     function version() {
71         return mysql_get_server_info();
72     }
73 
74     function close() {
75         return mysql_close();
76     }
77 
78 
79 //---------------------功能方法区--------------------------------
80 
81     function fn_insert($table,$name,$value){
82 
83         $this->query("insert into $table ($name) value ($value)");
84 
85     }
86     function fn_select($table){
87 
88         $this->query("select * from $table");
89 
90     }
91 
92 
93    }
94 
95 
96   $db =  new mysql(‘localhost‘,‘root‘,‘‘,‘db_tmlog‘,"utf-8");//数据库连接
97 
98 
99 ?>

 

php 类,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。