I need to copy description of the product from one table to another, everything works fine until the <img src="url" width="50%" height="50%" />
tag appears in the description. I have a script that copying descriptions of product one by one, with this script in cycle:
$rowParse = Parsing::find()->where(['art_post' => $value])->one();
$desc = $rowParse->description;
Yii::$app->db->createCommand("UPDATE `products` SET `description`=:desc WHERE `id_post`=:id && `art_post`=:art")
->bindValues([':desc'=>$desc, ':id'=>$id_post, ':art'=>$art_post])->execute();
If I do copying description of single product it works as needed - tag inserts with his attributes, but if i do, for example, 100 products in cycle, attributes width
and height
just disappears and it inserts just like <img src="url" />
Insertion of all other html-tags like span, strong, td, tr, p works normal.
I'm new to programming world, so I need help of big guys :D Thank you in advance
Ensure that the description
field in the products
table has a data type that supports storing HTML, such as TEXT
or LONGTEXT
. If the field is of a type like VARCHAR
with a limited length, it might truncate your HTML content.
Make sure that when you retrieve the description from the Parsing
table, the HTML content is not being encoded or escaped. Yii might automatically escape HTML entities when retrieving data from the database. You can use
Html::decode()
to ensure that the HTML is not encoded:
$desc = Html::decode($rowParse->description);
If you are updating a large number of records in a loop, you might want to consider wrapping your updates in a transaction to ensure data consistency:
$transaction = Yii::$app->db->beginTransaction();
try {
// Your loop and update logic here
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
}
This way, if an error occurs during the loop, the changes are rolled back, and your data remains consistent.
Add some logging statements to your code to see what values are being retrieved and updated. This can help you identify where the issue is occurring.
Yii::info('Description from Parsing table: ' . $desc, 'app');
You can then check the logs to see if the width and height attributes are present at the time of update.