参考:https://github.com/yii2-chinesization/yii2-zh-cn/blob/master/guide-zh-CN/db-dao.md
返回多行:
$command = $connection->createCommand('SELECT * FROM post');$posts = $command->queryAll();
$command = $connection->createCommand('SELECT * FROM post WHERE id=1');$post = $command->queryOne();
$command = $connection->createCommand('SELECT title FROM post');$titles = $command->queryColumn();
$command = $connection->createCommand('SELECT COUNT(*) FROM post');$postCount = $command->queryScalar();
$command = $connection->createCommand('UPDATE post SET status=1 WHERE id=1');$command->execute();
// INSERT $connection->createCommand()->insert('user', [ 'name' => 'Sam', 'age' => 30, ])->execute();// INSERT 一次插入多行 $connection->createCommand()->batchInsert('user', ['name', 'age'], [ ['Tom', 30], ['Jane', 20], ['Linda', 25], ])->execute();
$connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
$connection->createCommand()->delete('user', 'status = 0')->execute();
$command = $connection->createCommand('SELECT * FROM post WHERE id=:id');$command->bindValue(':id', $_GET['id']);$post = $command->query();
$command = $connection->createCommand('DELETE FROM post WHERE id=:id');$command->bindParam(':id', $id); $id = 1;$command->execute(); $id = 2;$command->execute();
$connection->createCommand()->createTable('post', [ 'id' => 'pk', 'title' => 'string', 'text' => 'text',]);