-1
 "UPDATE mytable SET column1 = value1, column2 = value2, ... WHERE status = 'pending'"; 

how can i write above query in magento2 ?

I try this.

$postData = $objectManager->create('vendor\module\Model\PostFactory');
        $arrayData = [ 
                        'status' =>'send'
                    ];
 $sql = $postData->create()
                 ->setData($arrayData)
                 ->load('status',array('eq'=>'pending'))
                 ->save();
2

1 Answer 1

1

Try this code

echo "<pre>";
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
//vendor\module\Model\PostFactory
$post = $objectManager->Create('\vendor\module\Model\ResourceModel\Post\Collection')->addFieldToFilter('status','pending');

foreach ($post as $key => $value) {
    //print_r($value->getId());
    $post_data = $objectManager->Create('\vendor\module\Model\Post')->load($value->getId());
    $post_data->setColumn1('value1');
    $post_data->setColumn2('value2');
    $post_data->save();
}

print_r($post->getData());

if column name is create_data then it should be like setCreateData() and column name is status then it should be like setStatus().

I Hope This Helps You

0

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.