简单的数据库链式操作的例子

<?php

/* 

@author Dishy 
数据库封装 
*/ 
class mysqldb{

private $host;
private $username;
private $password;
private $dbname;
private $sql;
private $select = true;
private $result;
private $array;

public function __construct($host,$username,$password,$dbname){
    $this->host = $host;
    $this->username = $username;
    $this->password = $password;
    $this->dbname = $dbname;
    $this->dbconnect();

}
/*
    数据库连接
*/
private function dbconnect(){
    mysql_connect($this->host,$this->username,$this->password);
    mysql_select_db($this->dbname);

}
/*
*执行sql语句
*
**/
public function query($sql){
        $this->sql = $sql;
        $this->result = mysql_query($this->sql);
        return $this;
}
/*
*
*$select = false时输出sql语句
*/
public function select($select= true){
    $this->select = $select;
    if($this->select){
        return $this->array =  $this->result();
    }else{
        return $this->sql;
    }
}
/**
*结果集
*/
private function result(){
    $array = mysql_fetch_array($this->result);
    return $array;
}

}

?> 
使用方法 include “./Api/datebase.php”; 
define('DB_HOST_NAME','localhost'); 
define('DB_HOST_USERNAME','root'); 
define('DB_HOST_PASSWORD','root'); 
define('DB_HOST_DB','jciot'); 
$Jciot_db = new mysqldb(DB_HOST_NAME,DB_HOST_USERNAME,DB_HOST_PASSWORD,DB_HOST_DB); 
$a = $Jciot_db->query('select * from jciot_member')->select(); 
var_dump($a);

?>`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值