$command->bindParam




$sql="INSERT INTO {{quiz_question}} (quiz_id, question_id, position) VALUES(".$quiz->quiz_id.",".$questionArr[0]['question_id'].",1)";


$connection->createCommand($sql)->execute();



above works, below does not work. i thought they are the same. Please why?




$sql="INSERT INTO {{quiz_question}} (quiz_id, question_id, position) VALUES(:quiz_id,:question_id,:position)";


$command=$connection->createCommand($sql);


$command->bindParam(":quiz_id",$quiz_id,PDO::PARAM_INT);


$command->bindParam(":question_id",$questionArr[0]['question_id'],PDO::PARAM_INT);


$command->bindParam(":position",1,PDO::PARAM_INT);


$command->execute();



Friend

Can you please try this?




$sql="INSERT INTO {{quiz_question}} (quiz_id, question_id, position) VALUES(:quiz_id,:question_id,:position)";


$command=$connection->createCommand($sql);


$command->bindParam(":quiz_id",$quiz_id,PDO::PARAM_INT);


$command->bindParam(":question_id",$questionArr[0]['question_id'],PDO::PARAM_INT);


$command->bindValue(":position",1,PDO::PARAM_INT);//Here I made the change to 'bindValue'


$command->execute();




Regrds.

hi, seenivasan

thanks for your reply!

but still doesnt work:(

btw, please what’s the difference between bindParm and bindValue?

Dear Aslan

I feel sorry that my little suggestion is not working for you.

This is what Yii documentation says!

This is in php documentation!