Welcome Guest, Not a member yet? Register   Sign In
Question on query bindings
#1

[eluser]stevefink[/eluser]
Hi all,

I couldn't find an Active Record way of writing this code, I'm curious however, what is the proper way to write this using query bindings?

Code:
function select_id($db) {
        // This function is responsible for returning the latest
        // id of the db snapshot for $db
        $sql = 'SELECT id FROM dbsnap
                    WHERE name like "%' . $this->db->escape($db) . '%"
                    ORDER BY id
                    DESC LIMIT 1';
        
        return $this->db->query($sql, $db);
    }

Thanks for any suggestions.
#2

[eluser]tonanbarbarian[/eluser]
Check the user guide

Queries :: Query Bindings
#3

[eluser]xwero[/eluser]
Code:
$this->db->select('id');
$this->db->from('dbsnap');
$this->db->like('name',$db);
$this->db->order_by('id','desc');
$this->db->limit(1);
$this->db->get();
#4

[eluser]stevefink[/eluser]
Thanks xwero. I wonder if method chaining will work to make this look a tad more elegant..


Something along the lines of:

Code:
$this->db->select('id')->from()->like()->order_by()->limit()->get();

etc... I'll have to try it. Thanks again.




Theme © iAndrew 2016 - Forum software by © MyBB