From 91bd244393ae40e302e3c1e0f7fedb01ddeee957 Mon Sep 17 00:00:00 2001 From: Rafael Bodill Date: Thu, 18 Sep 2014 22:05:08 +0300 Subject: Query builder in user login and controller --- application/controllers/user.php | 12 ++++++----- application/libraries/Duser/drivers/Duser_db.php | 27 +++++++++++------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/application/controllers/user.php b/application/controllers/user.php index 079f1665c..45bd93816 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -102,11 +102,13 @@ class User extends MY_Controller { $key = random_alphanum(32); - $this->db->query(" - INSERT INTO `apikeys` - (`key`, `user`, `comment`, `access_level`) - VALUES (?, ?, ?, ?) - ", array($key, $userid, $comment, $access_level)); + $this->db->set([ + 'key' => $key, + 'user' => $userid, + 'comment' => $comment, + 'access_level' => $access_level + ]) + ->insert('apikeys'); if (static_storage("response_type") == "json") { return send_json_reply(array("new_key" => $key)); diff --git a/application/libraries/Duser/drivers/Duser_db.php b/application/libraries/Duser/drivers/Duser_db.php index a58b5a298..258de1820 100644 --- a/application/libraries/Duser/drivers/Duser_db.php +++ b/application/libraries/Duser/drivers/Duser_db.php @@ -22,11 +22,10 @@ class Duser_db extends Duser_Driver { { $CI =& get_instance(); - $query = $CI->db->query(' - SELECT username, id, password - FROM `users` - WHERE `username` = ? - ', array($username))->row_array(); + $query = $CI->db->select('username, id, password') + ->from('users') + ->where('username', $username) + ->get()->row_array(); if (empty($query)) { return false; @@ -46,11 +45,10 @@ class Duser_db extends Duser_Driver { { $CI =& get_instance(); - $query = $CI->db->query(" - SELECT id - FROM users - WHERE username = ? - ", array($username)); + $query = $CI->db->select('id') + ->from('users') + ->where('username', $username) + ->get(); if ($query->num_rows() > 0) { return true; @@ -63,11 +61,10 @@ class Duser_db extends Duser_Driver { { $CI =& get_instance(); - $query = $CI->db->query(" - SELECT email - FROM users - WHERE id = ? - ", array($userid))->row_array(); + $query = $CI->db->select('email') + ->from('users') + ->where('id', $userid) + ->get()->row_array(); if (empty($query)) { show_error("Failed to get email address from db"); -- cgit v1.2.3-24-g4f1b