您的位置:首页 > 博客中心 > 数据库 >

关于我的php 框架,数据库层使用方法

时间:2022-03-14 00:29

 

框架中,数据库包含两层,一个zz_db.php , 一个zz_model.php

使用:

项目入口定义数据库参数:

//mysql
define (‘ZZ_MYSQL_HOST‘ , ‘127.0.0.1‘);
define (‘ZZ_MYSQL_USER‘ , ‘root‘);
define (‘ZZ_MYSQL_PW‘ , ‘‘);
define (‘ZZ_MYSQL_DB‘ , ‘microblog_home‘);  //暂时只有一个数据库操作
define (‘ZZ_MYSQL_TABLE_pre‘ , ‘mh_‘);

自己在项目的模型层中建立比如:UserModel.php extends zz_model.php

 

具体的各个方法所需的参数和返回的结果请看zz_model.php。

数据库操作方法:

增:

 $array = array(
 ‘username‘ => ‘123456789‘,
 ‘password‘ => ‘ttt‘,
 ‘reg_time‘ => time(),
 );

 $result = $this->insert($array);

 

查:(多条数据)

(返回二维数组或者空)

$field = array(‘username‘,‘password‘);
$option= array(
‘id‘ =>‘[<]‘.$a ,
‘[or]username‘ =>‘alazalaz‘,
‘password‘ =>‘[>=]ssss‘,
‘[or]mail‘ =>‘xxx‘,
);
$this->select($field , $option , 7);

select username,password from mh_user where id<‘2222‘ or username=‘alazalaz‘ and password>=‘ssss‘ or mail=‘xxx‘  limit 7

查:(一条数据)

同上(但返回的是一位数组或者空)

 $this->select_one($field , $option , 7);

 

 改:

$field = array(‘state‘=>1);

$option = array(‘id‘=>‘2‘);

$this->update($field,$option);

 

本类排行

今日推荐

热门手游