通过db执行sql语句
//添加Yii::app()->db->createCommand()->insert('tbl_user',array('username'=>'zhangsan','email'=>'zhangsan@zs.com'));
//修改Yii::app()->db->createCommand()->update('tbl_user',array('username'=>'Tester'),'id=:id',array(':id'=>3));
//删除Yii::app()->db->createCommand()->delete('tbl_user','id=:id',array(':id'=>2));
//查询 - 多条数据$users = Yii::app()->db->createCommand()
->select('*')
->from('tbl_user')
->queryAll();
//查询一条数据
$sql ="SELECT id,name FROM tbl_user WHERE email='123@qq.com'";
$users=Yii::app()->db->createCommand($sql)->queryRow();
php返回数据给ajax
echo json_encode($array);
php中json_decode()和json_encode()的使用方法
javascript 将json字符串转换为json对象的方法解析 (待搞懂)
网友评论