Home > Article > Backend Development > Yii uses framework to execute sql method problem
I found a problem today, I don’t know why? The code is as follows
<code>//这是一开用的方法 $data = Admin::findOne($id)->toArray(); //这是今天刚换的写法 $data = Admin::find()->where(['id'=>$id])->asArray()->one();</code>
As above, I started using the first way of writing. I don’t know what happened today but the first way of writing was wrong. Just switch to the second one. So depressing! ! ! Ask the great god
I found a problem today, I don’t know why? The code is as follows
<code>//这是一开用的方法 $data = Admin::findOne($id)->toArray(); //这是今天刚换的写法 $data = Admin::find()->where(['id'=>$id])->asArray()->one();</code>
As above, I started to use the first way of writing. I don’t know what happened today, but the first way of writing was wrong. Just switch to the second one. So depressing! ! ! Ask the great god
Thank you for the invitation. Your first way of writing and your second way of writing are both correct. Are you treating your $data as an array? If so, there will be problems. Because your first way of writing returns null
if no data can be queried, and the second way of writing returns an empty array array()
if no data can be queried. Take a look at how you process the returned data.