How can I convert this query to active record?
"UPDATE table_user SET email = '$email', last_ip = '$last_ip' where username = '$username' and status = '$status'";
I tried to convert the query above to:
$data = array('email' => $email, 'last_ip' => $ip); $this->db->where('username',$username); $this->db->update('table_user',$data);
How about using the where clausa status?
# must i write db->where two times like this? $this->db->where('username',$username); $this->db->where('status',$status);
I also tried this:
$this->db->where('username',$username,'status',$status);
SQL injection is an attack made on database query. In PHP, we are use mysql_real_escape_string() function to prevent this along with other techniques but CodeIgniter provides inbuilt functions and libraries to prevent this.
CodeIgniter Select Query with $this->db->where_in()The where_in() function is used to generate WHERE field IN ('item', 'item') SQL query string joined with AND if appropriate.
you can use an array and pass the array.
Associative array method: $array = array('name' => $name, 'title' => $title, 'status' => $status); $this->db->where($array); // Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
Or if you want to do something other than = comparison
$array = array('name !=' => $name, 'id <' => $id, 'date >' => $date); $this->db->where($array);
Yes, multiple calls to where() is a perfectly valid way to achieve this.
$this->db->where('username',$username); $this->db->where('status',$status);
http://www.codeigniter.com/user_guide/database/query_builder.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With