Yii uses framework to execute sql method problem

WBOY
Release: 2016-09-19 09:16:29
Original
1117 people have browsed it

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>
Copy after login
Copy after login

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

Reply content:

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>
Copy after login
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template