0

Direct SQL Query in Magento 2

   $sql = "UPDATE ".$table." SET `value` = '".$newMetaTitleValue."' WHERE  value_id = ".$id;
 $connection->query($sql); 

dispaly result

xception #0 (Zend_Db_Statement_Exception): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Sky-ukeydeal' WHERE  value_id = 9718' at line 1, query was: UPDATE catalog_product_entity_varchar SET `value` = 'No Man's Sky-ukeydeal' WHERE  value_id = 9718
Exception #1 (PDOException): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Sky-ukeydeal' WHERE  value_id = 9718' at line 1

2 Answers 2

0

Try This one

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');

$connection = $resource->getConnection();

$tableName = $resource->getTableName('employee');

$sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12";

$connection->query($sql);`

0

Did you try this

 $sql = "Update " . $your_table_name . "Set column_name = '.$your_value.' where entity_id = ".$id;
2
  • yes, I tryed ,it will dispaly error .UPDATE catalog_product_entity_varchar SET value = '.No Man's Sky-ukeydeal.' WHERE value_id = 9718
    – sq y
    Commented Jul 22, 2022 at 5:46
  • Please share your code for update query Commented Jul 22, 2022 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.