andFilterWhere()函数找不出某个int类型字段为0的数据
2016-11-12 17:17
429 查看
首先本人刚接触YII2, 小知道都统计起来的。
该字段的值只有0和1。数据库中页确实存在该字段值为0的数据,但是这样写提示没有找到数据,把0改成1能找出该字段值为1的数据。如果不加andFilterWhere语句,那么会正常显示所有的数据,包括is_delete字段为0的数据。
接下来分析
原因是按照你写的那样, 最终生成的
有意思的是,
我试了下,
其他时候均能查到, 但是此种情况下, 不会用到索引.
$client = $_POST['client'];
$this->model->attributes
=$client;
$this->model->create_user =$create_user;
$this->model->create_date =$create_date;
$this->model->save();
$customer_id =$this->model->attributes['id']; //获取save插入后的id
上面是半年前写的,有不足,下面重新写着说明一下。
$customer =Customer::model();
$post_data = $_POST['client'];
$customer->attributes =$post_data;
$customer->create_user =Yii::app()->user->getId();
$customer->create_time =time();
$customer->save();
$customer_id = $customer->id; //这样获取save插入后的id最方便
$customer_id =$customer->attributes['id']; //这样也可以 获取save插入后的id
$customer_info = $customer->attributes; //这样可以获取save插入后的相应model所有属性
直接 $this->model->id 不是更简单?
http://blog.sina.com.cn/s/blog_ea7f2ce40102wods.html
1.按钮的id为btnzhuce
==》 控制按钮为禁用:
$("#btnzhuce").attr({"disabled":"disabled"});
==》控制按钮为可用
$("#btnzhuce").removeAttr("disabled");//将按钮可用
http://blog.csdn.net/dc769319/article/details/53022570 不修改源文件 直接 刷新验证码
http://www.yiichina.com/tutorial/410 http://www.360us.net/article/17.html 验证码的使用
https://segmentfault.com/a/1190000005910783 重写源生验证码
先设置
再
这样这默认选中了
andFilterWhere()函数找不出某个int类型字段为0的数据
$query = Equip::find()->andFilterWhere(['and','is_delete',0]);
该字段的值只有0和1。数据库中页确实存在该字段值为0的数据,但是这样写提示没有找到数据,把0改成1能找出该字段值为1的数据。如果不加andFilterWhere语句,那么会正常显示所有的数据,包括is_delete字段为0的数据。
先说解决办法, 改成下面的形式 :
$query = Equip::find()->andFilterWhere(['is_delete' => 0]); 或者 $query = Equip::find()->andFilterWhere(['and', ['is_delete' => 0]]);
接下来分析 为什么会出现这么有趣的现象
is_delete = 1
可以达到预期, 不加这个条件
也可以达到预期, 偏偏 is_delete = 0
有问题
原因是按照你写的那样, 最终生成的sql会是 :
select * from table where is_delete and 0 (或者1);
有意思的是,
select * from table where fieldName这样的语句并不会报错.
我试了下,
fieldName为空, 为null, 为0的时候, 查不到.
其他时候均能查到, 但是此种情况下, 不会用到索引.
yii 数据model->save()相关
$this->model = Customer::model();$client = $_POST['client'];
$this->model->attributes
=$client;
$this->model->create_user =$create_user;
$this->model->create_date =$create_date;
$this->model->save();
$customer_id =$this->model->attributes['id']; //获取save插入后的id
上面是半年前写的,有不足,下面重新写着说明一下。
$customer =Customer::model();
$post_data = $_POST['client'];
$customer->attributes =$post_data;
$customer->create_user =Yii::app()->user->getId();
$customer->create_time =time();
$customer->save();
$customer_id = $customer->id; //这样获取save插入后的id最方便
$customer_id =$customer->attributes['id']; //这样也可以 获取save插入后的id
$customer_info = $customer->attributes; //这样可以获取save插入后的相应model所有属性
直接 $this->model->id 不是更简单?
http://blog.sina.com.cn/s/blog_ea7f2ce40102wods.html
yii model->save() 返回false
yii model层操作总结 http://www.cnblogs.com/xieqian111/p/5212505.html
$model->save()执行时,如何不要验证?
[code]public boolean save(boolean $runValidation=true, array $attributes=NULL) $model->save(false); //不验证1.按钮的id为btnzhuce
==》 控制按钮为禁用:
$("#btnzhuce").attr({"disabled":"disabled"});
==》控制按钮为可用
$("#btnzhuce").removeAttr("disabled");//将按钮可用
http://blog.csdn.net/dc769319/article/details/53022570 不修改源文件 直接 刷新验证码
http://www.yiichina.com/tutorial/410 http://www.360us.net/article/17.html 验证码的使用
https://segmentfault.com/a/1190000005910783 重写源生验证码
先设置
$model->allow_comment = 1
再
<?= $form->field($model, 'allow_comment')->checkbox([ 'label' => '允许评论']) ?>
这样这默认选中了
相关文章推荐
- MySQL数据类型:TINYINT,SMALLINT,MEDIUMINT,INT,INTEGER,BIGINT;text,longtext,mediumtext,ENUM,SET等字段类型区别
- SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int
- 自定义函数名数据类型typedef int (init_fnc_t) (void);
- Greendao 3.X 数据库升级,新增int、long数据类型字段NOT NULL 解决方案
- SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int
- mongo 对数据很严格 在使用组装条件的时候需要注意 字段的类型, 分享几个转换的函数
- SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int
- 在将 varchar 值 'select * from soft where id=' 转换成数据类型 int 时失败
- (转载)MySQL数据类型:TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER等字段类型区别
- SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int
- Arduino中数据类型转换 int转换为char 亲测好使,itoa()函数
- 更新数据库所有表的某一个指定字段 ,附加对‘将 varchar 值转换为数据类型为 int 的列时发生语法错误’处理方法
- mysql5.7基础 insert 插入int类型的字段中的数据可以用单引号包裹
- Python数据类型之间的转换 函数 描述 int(x [,base]) 将x转换为一个整数 long(x [,base] ) 将x转换为一个长整数 float(x) 将x转换到一个浮点数
- 关于sql条件语句where id in (@参数)执行报错问题(转换成数据类型 int 时失败)(
- 创建mysql数据表时,字段的int类型长度问题
- 利用sqlite创建一个数据user,其含有一张表person,该person表中含有三个列,其中第一字段为主键int类型的,其他两个字段自定义数据类型和名称。
- Arduino中数据类型转换 int转换为char 亲测好使,itoa()函数
- Sql Server关于字段中的数据类型
- 修复identity 类型字段数据的跳跃