zoukankan      html  css  js  c++  java
  • 简单的类php和mysql


    <?php
    header("content-type: text/html; charset=utf-8");
    /*__construct()初始化
    *php+mySql类
    */

    class mysql{
    private $host;
    private $name;
    private $pass;
    private $table;//数据库表
    private $ut;
    //初始化函数
    function __construct($host,$name,$pass,$table,$ut){
    $this->host = $host;
    $this->name = $name;
    $this->pass = $pass;
    $this->table = $table;
    $this->ut = $ut;
    $this->connect();
    }
    //建立连接数据库的函数
    function connect(){
    //mysql_connect($this->host,$this->name,$this->pass) or die (mysql_error());
    $link = mysql_connect($this->host,$this->name,$this->pass) or die (mysql_error());
    // echo "连接成功";
    mysql_select_db($this->table,$link) or die ("没有数据库".$this->table);
    mysql_query("SET NAMES".$this->ut); //这种插入会乱码.因为编码格式要加引号
    mysql_query("SET NAMES '$this->ut'");
    }

    //执行mysql语句函数
    function query($v){
    return mysql_query($v);
    }
    //封装错误提示信息
    function errora(){
    return mysql_error();
    }

    //====================
    function fn_insert($table,$name,$value){
    //表名,字段名,字段值
    $this->query("insert into $table ($name) value ($value)");

    }

    }
    $db = new mysql("localhost","root","","laok","utf8");
    $db->fn_insert('test','id,uid,regdate,remark',"'','我插入的信息23',now(),''");

    ?>

  • 相关阅读:
    四则运算2
    四则运算1
    学习进度条
    Mat数据结构
    Markdown语法
    C++继承和派生
    C++智能指针
    clion配置ROS
    视觉十四讲:第六讲_g2o图优化
    视觉十四讲:第六讲_ceres非线性优化
  • 原文地址:https://www.cnblogs.com/laok/p/4582148.html
Copyright © 2011-2022 走看看