YzmCMS帮助手册(适用于YzmCMS3.0以下版本),3.0以上版本请转至
https://www.yzmcms.com/dongtai/37.html
//header("Content-Type:text/html;charset=utf-8"); //实例化一个对象,只传入表名即可; $db = M('user'); //添加内容[成功:返回自动增长的ID,失败:false] //$db->insert(array('name'=>'姓名','sex'=>'男')); //$db->insert(array('name'=>'姓名','sex'=>'男'),'1'); //第二个参数选填 如果存在,并为真值 则开启实体转义 //删除内容[返回影响行数] //$db->delete(array('id>'=>'15')); //$db->delete(array(3,4,5), true); //第二个参数存在时,第一个参数为索引数组,批量删除多个 //更新内容[返回影响行数] //$db->update(array('name'=>'姓名','sex'=>'男123'),array('id'=>'10')); //$db->update(array('name'=>'姓名','sex'=>'aaa'),array('id'=>'10'),'1'); //第三个参数选填 如果存在,并为真值 则开启实体转义 //$db->update('click=click+1',array('id'=>"1")); //第一个参数不是数组,类似于更新文章点击数的功能 //查询内容 select方式[返回二维数组] //$result = $db->select(); //$result = $db->field('uname,id')->select(); //$result = $db->where(array('name'=>'%php%'))->select(); //like 查询 //$result = $db->join('`yzm_admin` ON yzm_admin.id=yzm_admintype.id')->where(array('id'=>'1'))->select(); //join 联合查询 //$result = $db->where("typeid in (1,2)")->select(); //SQL : select * from user where typeid in (1,2) //$result = $db->where(array('name'=>'%php%'))->limit('0,5')->select(); //like 查询 //$result = $db->where(array('name'=>'%php%'))->limit('0,5')->order('id desc')->select(); //like 查询 //$result = $db->where(array('sex'=>'男'))->limit('0,5')->select(); //$result = $db->field('uname,id')->where(array('sex'=>'男'))->limit('0,3')->order('id desc')->select(); //$result = $db->field("sex ,count(sex),avg(height),sum(height) ")->group("sex")->having(" avg(height) >160")->select(); //$result = $db->field("sex ,count(sex) as '总个数',avg(height) as '平均身高',sum(height) as '总身高' ")->group('sex')->select(); //$result = $db->field("sex ,count(sex) as '总个数',avg(height) as '平均身高',sum(height) as '总身高' ")->group("sex")->having(" 平均身高 >160")->select(); //查询内容 find方式[返回一维数组] //$result = $db->find(); //$result = $db->field('uname,id')->find(); //$result = $db->where("typeid in (1,2)")->find(); //SQL : select * from user where typeid in (1,2) limit 1 //$result = $db->field('id,name,height')->where(array('sex'=>'男'))->find(); //$result = $db->join('`yzm_admin` ON yzm_admin.id=yzm_admintype.id')->where(array('id'=>'1'))->find(); //join 联合查询 //$result = $db->field('uname,id')->where(array('sex'=>'男'))->order('id desc')->find(); //查询记录数[返回记录行数] //$result = $db->total(); //$result = $db->where(array('age>'=>'12'))->total(); //$result = $db->join('`yzm_admin` ON yzm_admin.id=yzm_admintype.id')->where(array('age>'=>'12'))->total(); //自定义执行SQL语句 [yzmcms 代表表前缀] //$db->query("select * from yzm_admin"); //获取一维数组,一条结果 //$db->fetch_array($db->query("select * from yzm_admin")); //获取二维数组 //$db->fetch_all($db->query("select * from yzm_admin")); //用于调试程序,输入最后一条SQL语句 //$db->lastsql();