Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the equivalent to getLastInsertId() in Cakephp?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.27k
    Comment on it

    Hello if you want to get last insert id or something equivalent to this you can try following steps:-

    Lets take this example, Here I just inserted the field in column

     $data = array('menuName' =$_REQUEST['menuname'])
        $this->Menu->create();
        $this->Menu->save($data);
        $id = $this->Menu->getLastInsertId();
    

    And you want the id on which this last record has been inserted, for this you can do it in many ways but the best method for fetching the last inserted id is like

    $this->User->id; 
    

    Here the model name is user, and when its updated it will store the inserted id in variable id,

    And you can also do this by giving the model function name then it will return the last insert id and model data also

    $this->User->getLastInsertId(); $this->User->getInsertID(); 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: