调用未知方法:yii\db\Command::select()



请帮帮我,我将从带有子字符串的表中获取一些数据,但显示此错误。

Calling unknown method: yiidbCommand::select()

这是我的代码:

<table>
<thead>
<td>Permission</td>
<td>Status</td>
<td>Remove</td>
</thead>
<tbody>
<?php  
$a = Yii::$app->db->createCommand()->select('name as item')->from('auth_item')->query();
foreach ($a as $key => $value) {
$c = $a.substring(1);
?>
<td><?php echo $c ?></td>
<?php } ?>
</tbody>
</table>

您的要求只是获取数据。Yii::$app->db->createCommand()主要用于插入和更新案例。

您可以尝试以下代码 -

use yiidbQuery;
$query = new Query();
$query->select('name as item')->from('auth_item')->orderBy('created_at');
$command = $query->createCommand();
$records = $command->queryAll();
// print_r($records); // expected results

快速简化此处的其他选项和详细文档

将变量传递到 where 子句 yii2

$query = new Query();

$query = new Query();
$query->select('mail')
->from('table') 
->where(['column'=>$cond_1, 'column2' => 'cond_2']);
$command = $query->createCommand();
$record= $command->queryAll();
$email = $record[0]['mail'];

最新更新