//tp 数据库模型
//实例化基本模型 Model
// $user = new Model(‘gbook’);
// $date = $user->select();
// var_dump($date);
//实例化用户自定义模型,继承Model
//D 是 M 的高级方法 如果D找不到的话 会自动使用M方法
$user = D(‘gbook’);
echo $user->getinfo();
//新建一个公共的模型
//新建一个空模型
$model = M();
$model->query($sql);//只能查询语句select
$model->execute($sql);//只能插入 更新 insert update
$this->display(‘user’);.
array(
‘user’=>’xiaoming’,
‘password’=>’123456’,
‘sex’=>’0,
),
******************数据库添加数据
public function user() {
$date = array(
array(
‘user’=>’tom’,
‘password’=>’123456’,
‘sex’=>’0’,
),
array(
‘user’=>’cidny’,
‘password’=>’123456’,
‘sex’=>’1’,
),
array(
‘user’=>’jack’,
‘password’=>’123456’,
‘sex’=>’0’,
),
);
M(‘gbook’)->add($date);
M(‘gbook’)->addall($date);//批量添加二维数据库
返回受影响行数 ID值
***********************************************查询
1.字符串直接查询
$data = M(‘user’)->WHERE(‘id’=1)->select();
2.通过数组的方式查询
$where[‘字段名’] = ‘值’
$where[‘_logic’] = ‘or’; //设置逻辑值
$data = M(‘user’)->WHERE(‘id’=1)->select();
3.表达式 eq neq gt ngt lt nlt
******************************更新数据
$update[‘ziduan’] = ‘值’ //要更新的值
$where[‘id’] = 1 //条件
$date = M(‘表名’)->where($where)->save($update)
php foeahc循环的时候value当变量名
[
‘d’=>4
],
‘b’=>[
‘f’=>4
],
‘c’=>[
‘g’=>4
]
];
echo ‘
';foreach ($a as $key => $value) {
$value['e'] = 5;//$a['a']['e'] = 5;
//print_r($value);
}print_r($a);
发表评论