Search code examples
yii2

Yii2 insert query with bindparam for sql injection


I want use but not work please help me.

$sql = Yii::$app->db("INSERT INTO posts(name) VALUES(:name)");
$sql->bindValues([':name' => 'John']);
$sql->execute();

Solution

  • try create command exceute

        Yii::$app->db->createCommand('INSERT INTO posts(name) VALUES(:name)')
              ->bindValues([':name' => 'John'])->execute();