码迷,mamicode.com
首页 > Web开发 > 详细

php 类

时间:2014-06-08 18:52:24      阅读:431      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

bubuko.com,布布扣
 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 ?>
bubuko.com,布布扣

 

php 类,布布扣,bubuko.com

php 类

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/mrcln/p/3776228.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!