N
N
Nikolai Novosad2015-12-06 15:55:15
Yii
Nikolai Novosad, 2015-12-06 15:55:15

Yii2 Write such an insert query?

Hello.
Please show how to get the data in the controller to write them to the database.
Here is the request:

INSERT INTO review(review_date, review_name, product_id, review) VALUES('review_date', 'review_name', 'product_id', 'review')

I've been fighting for an hour now, but it doesn't come out.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Khomenko, 2015-12-06
@nik_neman

Yii::$app->db->createCommand()->insert('review', [
    'review_date' =>$reviewDate ,
    'review_name' => $reviewName,
    'product_id' => $productId,
    'review' => $review,
])->execute();

or create an entity and save via ActiveRecord
$review = new Review([
    'review_date' =>$reviewDate ,
    'review_name' => $reviewName,
    'product_id' => $productId,
    'review' => $review,
]);
$review->save();

Are you sure you read the documentation ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question