Tp day 2

来源:互联网 发布:建工金源网络培训平台 编辑:程序博客网 时间:2024/06/06 07:47

数据库配置文件

shop/common/conf/config.php

控制器创建模型

new \Model\UseModel();

如果表明跟带后缀的名称不一样,只要在声明模型的时候加上

$protected trueTableName='         '


D 跟 new  

D智能操作数据表,如果需要有其他功能,比如增加判断就只能用new

数据的基本操作

查询 select

$goods->select();select * from 'sw_goods'

$goods->select(12); select * from 'sw_goods' where 'goods_id' =12;

$goods->select (12,13,34,35);selext * from 'sw_goods' where 'goods_id' in ('12','13','3'4,'35');

{$v@iteration} 从一开始



具体的数据操作方法使用


select goods_brand_id ,conut(*) from sw_goods group by goods_brand_id;

select goods_brand_id ,avg(goods_price) from sw_goods  group by goods_brand_id;



where gen having de qubioe

where 条件字段必须是数据表中存在的

having 条件字段必须在结果集中存在


数据添加

array方式

ar方式



$array=aray(

"goods_name"=>'nihao',

'goods_id'=>12,

)

$goods->add($array);



$goods->goods_name='nihao';

$goods->add();


删除

¥model->where()->delete

$model->goods_id=12;

$model->delete();

$model->delete(12);


原生sql语句

$model->query($sql);  查询,返回一个二维数组

$model->execute($sql);增删改 返回受影响的数据




$_POST['user_hobby']=implode(',',$_POST['user_hobby']);



protected $patchValidate=true;

protected $_validate=array(

)

array(验证字段,验证规则,错误提示【验证条件,附加规则,验证时间】)