Reputation: 21
After too many research online on how to insert data on a specific table I failed to find any beginning.
I have a table name called yii_tst59
and it has the following fields:
- id
-idnum
-name
I read some tutorial in Yii
docs but those are existing tables.
What I want to do is simple , insert data in yii_tst59
.
what should I do in /controllers/SiteController.php
, in the /models
and in /view
I just need to know how to start, please help.
Upvotes: 2
Views: 237
Reputation: 487
The best way to do it, if you want to do it with ActiveRecords is:
Use that model to populate the record and save it (see below)
public function actionTest(){
$testModel = new Yii_tst59();
$testModel->id = 1;
... set other variables...
$testModel->save()
}
If you do not want to use active records you can insert it directly via SQL but I would not recommend it, specially if you're using Yii for the first times.
Upvotes: 2
Reputation: 815
you can directly insert your data using following format
$sql = 'Your insert query';
Yii::app()->db->createCommand($sql)->execute();
Upvotes: 0