class User
{
public $id;
public $name;
}
$sql = "SELECT id, name FROM users";
$sth = Yii::$app->db->pdo->prepare($sql);
$sth->execute();
$sth->fetchAll(PDO::FETCH_CLASS, 'User');
class User extends \yii\base\Object
{
public $id;
public $name;
}
$query = new \yii\db\Query;
$query->select(['id', 'name'])->from('users');
$command = $query->createCommand(Yii::$app->db);
$reader = $command->query();
while ($user = $reader->readObject(User::className(), [])){
$users[] = $user;
}
$command = (new \yii\db\Query())
->select(['id', 'email'])
->from('user')
->where(['last_name' => 'Smith'])
->limit(10)
->createCommand();
// показать SQL запрос
echo $command->sql;
// показать привязываемые параметры
print_r($command->params);