aslan
(Aslan Shek)
September 8, 2012, 2:39pm
1
$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();
seenivasan
(Chellamnivas)
September 8, 2012, 2:49pm
2
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.
aslan
(Aslan Shek)
September 8, 2012, 2:54pm
3
seenivasan:
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?
seenivasan
(Chellamnivas)
September 8, 2012, 3:04pm
4
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!
bool PDOStatement::bindValue ( mixed $parameter , mixed $value [, int $data_type = PDO::PARAM_STR ] )
Binds a value to a corresponding named or question mark placeholder in the SQL statement that was used to prepare the statement.