I want to execute a query in a view page in Yii, here is my code:
$connection=Yii::app()->db;
$connection->active=true;
$sql = "insert into news(idNews, news, display) values('', 'anything', 0)";
$command=$connection->createCommand($sql);
$command->execute();
but nothing is happened, what is the error with my code?
createCommandreturns a normal PDO. So at first you need check if$command->execute()true, if not you have check what error mysql reports.idNewsis auto incremental, you don't have to pass anything about it, also check/runtime/application.logif an error happend and you missed it