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

问题描述 投票:-1回答:2

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

Calling unknown method: yii\db\Command::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>
yii2 yii2-advanced-app
2个回答
0
投票

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

您可以尝试以下代码 -

use yii\db\Query;
$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

Quick Simplified other option heredetailed docs


0
投票

在子句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'];
© www.soinside.com 2019 - 2024. All rights reserved.