How to get data from your database using the model by Query Builder in CodeIgniter 4

To do this, follow the few simple steps as describe below.How to get data from your database using the model by Query Builder in CodeIgniter 4
Step 1 Create Model and inside it, create a function.
For example, we have created a model name SaveModel.
<?php

namespace App\Models;

use CodeIgniter\Model;

class SaveModel extends Model
{

public function GetData(){
        //code here 
    }


}
Step 2 Paste the below code to select Maximum ID from table named ‘usertable’.
$builder = $this->db->table("usertable");
            $builder->selectMax('id');         
            $query = $builder->get();
            return $query->getResult();
Here is the complete code.
<?php

namespace App\Models;

use CodeIgniter\Model;

class SaveModel extends Model
{

public function GetData(){
        $builder = $this->db->table("usertable");
            $builder->selectMax('id');         
            $query   = $builder->get();
            return $query->getResult();
    }


}
Now call the above function wherever you want to use it. Below is sample how can you call the above function.
$model= new SaveModel();
$maxId = $model->GetData();

get data from database using query builderexpoundsofttechsolution