summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Bodill <rafi@sortex.co.il>2014-09-18 21:05:08 +0200
committerRafael Bodill <rafi@sortex.co.il>2014-09-18 21:05:08 +0200
commit91bd244393ae40e302e3c1e0f7fedb01ddeee957 (patch)
tree623763097ed2a7bb41f2ed53250d8cab22edeafa
parentd2c309aee8189a5d6c2a3fcb0a05ea694d7b646e (diff)
Query builder in user login and controller
-rw-r--r--application/controllers/user.php12
-rw-r--r--application/libraries/Duser/drivers/Duser_db.php27
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");