A command object is usually created by calling [[Connection::createCommand()]].
The SQL statement it represents can be set via the [[sql]] property.
To execute a non-query SQL (such as INSERT, DELETE, UPDATE), call Command::execute.
To execute a SQL statement that returns result data set (such as SELECT),
use Command::queryAll, Command::queryOne, Command::queryColumn, Command::queryScalar, or Command::query.
For example,
~~~
$users = $connection->createCommand('SELECT * FROM user')->queryAll();
~~~
Command supports SQL statement preparation and parameter binding.
Call Command::bindValue to bind a value to a SQL parameter;
Call Command::bindParam to bind a PHP variable to a SQL parameter.
When binding a parameter, the SQL statement is automatically prepared.
You may also call Command::prepare explicitly to prepare a SQL statement.
Command also supports building SQL statements by providing methods such as Command::insert,
Command::update, etc. For example,
~~~
$connection->createCommand()->insert('user', [
'name' => 'Sam',
'age' => 30,
])->execute();
~~~
To build SELECT SQL statements, please use QueryBuilder instead.