6

I'm using below code

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$select = $connection->select()
        ->from(
        ['ce' => 'customer_entity']
);
$data = $connection->fetchAll($select);

It's working fine. It returns all customer fields. I would like to select only First Name, Last Name & Email.

Instead of select(), which function we need to use & how?

11

Try following way:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$select = $connection->select()
    ->from(
        ['ce' => 'customer_entity'],
        ['firstname', 'lastname', 'email']
    );
$data = $connection->fetchAll($select);
  • How will we add where condition in this? – Amrit Pal Singh May 22 '18 at 6:09
  • @AmritPalSingh - Taking reference from Sohel Rana's query after select statement(& before fetchAll) you can add where clause ie. $select->where('customer_id = ?', (int)$cust_id); – GunJan Mehta Nov 26 '18 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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