/**
* Creates a command for execution.
* @param string $sql the SQL statement to be executed
* @param array $params the parameters to be bound to the SQL statement
* @return Command the DB command
*/
function db($sql = null, $params = [])
{
return new \Yii::$app->db->createCommand($sql, $params);
}
and then
db()->....
But autocomplete code in PHPStorm does not work in this example.
So, this is how it works for me, including autocomplete in PHPStorm:
/**
* Creates a command for execution.
* @param string $sql the SQL statement to be executed
* @param array $params the parameters to be bound to the SQL statement
* @return \yii\db\Command the DB command
*/
function db($sql = null, $params = [])
{
return new \Yii::$app->db->createCommand($sql, $params);
}
...
db()->...