• 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 ?>
  • 相关阅读:
    MIPAV
    SPM12manual,统计部分(8-10)笔记
    Django中ORM介绍和字段及字段参数
    Django的路由系统
    django 连接mysql报错
    django启动创建用户失败
    django ORM操作
    Django创建App报错
    Web框架
    Bootstrap框架(组件)
  • 原文地址:https://www.cnblogs.com/mrcln/p/3776228.html
Copyright © 2020-2023  润新知