zoukankan      html  css  js  c++  java
  • 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 ?>
  • 相关阅读:
    Mysql JSON 新特性用法
    fastjson 使用技巧
    kafka 笔记
    nginx 使用教程
    spring boot 和 spring mvc 使用 jackson 包处理 忽略 null 字段返回
    jmeter 安装使用
    windows 下千万不要用 git的“换行符自动转换功能”
    ps grep awk 结合 xargs kill进程
    linux发行版版本及内核查看
    union 跟 order by同时使用
  • 原文地址:https://www.cnblogs.com/mrcln/p/3776228.html
Copyright © 2011-2022 走看看