yii2无符合条件的查询结果总结。

无符合条件的查询结果

1.使用findone()

返回null

2.使用find()

select不使用字段别名

  • find()->select([‘num’])->asArray()->one()
    返回null
  • find()->select([‘num’])->asArray->all()
    返回空数组[ ]
  • find()->select([‘num’])->where()->column()
    返回空数组[]
  • find()->select([‘num’])->where()->scalar()
    返回false

select使用字段别名

  • find()->select([‘num’ => ‘sum(num)’])->asArray()->one()
    返回[‘num’ => null]
  • find()->select([‘num’ => ‘sum(num)’])->asArray->all()
    返回空数组[ [‘num’ => null]]
  • find()->select([‘num’ => ‘sum(num)’])->where()->column()
    返回空[null]
  • find()->select([‘num’ => ‘sum(num)’])->where()->scalar()
    返回null

你可能感兴趣的:(Yii2)