magento-1.9 – Customer ID with Email ID SQL Query

magento-1.9sql

I just want to fetch customer id with email as parameter from the mysql database. How can i hit the sql query to get the customer_id.

 $passphrase = "password";
 $salt = "SC";
 $password = md5($salt . $passphrase) . ":SC";

 $write->query("update customer_entity_varchar set value='$password' where entity_id=$customer_id and attribute_id in (select attribute_id from eav_attribute where attribute_code='password_hash' and entity_type=1)");

This is the code which i been using to update password , I need dynamic customer id.

this is full code

<?php 
include('app/Mage.php');
Mage::app();  
if($_POST && $_POST["email"])
    {


          $collection = mage::getModel('customer/customer')->getCollection()      ->addAttributeToSelect('email')
         ->addAttributeToFilter('myemail@domain.com') 
         ->addAttributeToSort('email', 'ASC');
          var_dump((string)$collection->getSelect());
                         die();

                       $passphrase = "password";
                       $salt = "SC";
                       $password = md5($salt . $passphrase) . ":SC";

                       $write->query("update customer_entity_varchar set value='$password' where entity_id=$customer_id and attribute_id in (select attribute_id from eav_attribute where attribute_code='password_hash' and entity_type=1)");


                      $send_data["success"]=true;
                      $send_data["message"]="Login Success";
                      $send_data["customer_id"]=$customer_id;

    }
    else
    {
            $send_data["success"]=false;
            $send_data["message"]="Enter both Email and Password";
    }
     Mage::getSingleton('customer/session')->loginById($send_data["customer_id"]);
    echo json_encode($send_data);

    ?>

Best Answer

You can try below code in magento

$collection = mage::getModel('customer/customer')->getCollection()
 ->addAttributeToSelect('email')
 ->addAttributeToFilter('email',$_POST['email']) 
 ->addAttributeToSort('email', 'ASC');
 var_dump((string)$collection->getSelect());

this will print following query

SELECT e.*, at_firstname.value AS firstname FROM customer_entity AS e INNER JOIN customer_entity_varchar AS at_firstname ON (at_firstname.entity_id = e.entity_id) AND (at_firstname.attribute_id = '5') WHERE (e.entity_type_id = '1') AND (at_firstname.value = 'sander') ORDER BY e.email ASC
Related Topic