What does the colon before the literal in the SQL expression mean?

What does it mean to use " : " before a variable?

For example, :userIdin this code:

public function removeUser($userId)
{
 $command = Yii::app()->db->createCommand();
 $command->delete(
 'tbl_project_user_assignment',
 'user_id=:userId AND project_id=:projectId',
 array(':userId'=>$userId,':projectId'=>$this->id));
}

This is PHP, MySQL code in the Yii framework.

+5
source share
3 answers

The double is a generic character that indicates the placeholder for the value of a variable in an SQL statement. In this case, those values are replaced with placeholders userIdand project_idat runtime. This is great for preventing SQL injection vulnerabilities.

+6
source

: userId is a placeholder

According to the Yii documentation for the SQL statement :

: .

+3

As thaidiotguy mentions, it is characteristically used with prepared statements, especially with PDO. In PDO, the colon indicates that the next is a named parameter.

0
source

All Articles