Skip to content

Instantly share code, notes, and snippets.

@tony1223
Created October 15, 2012 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony1223/3893198 to your computer and use it in GitHub Desktop.
Save tony1223/3893198 to your computer and use it in GitHub Desktop.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class UserModel extends CI_Model {
function __construct()
{
parent::__construct();
}
function insert($account,$password){
$this->db->insert("user",
Array(
"account" => $account,
"password" => $password
));
}
function checkUserExist($account){
$this->db->select("COUNT(*) AS users");
$this->db->from("user");
$this->db->where("account", $account);
$query = $this->db->get();
return $query->row()->users > 0 ;
}
public function getUser($account,$password){
$this->db->select("*");
$query = $this->db->get_where("user",Array("account" => $account, "password" => $password ));
if ($query->num_rows() > 0){ //如果數量大於0
return $query->row(); //回傳第一筆
}else{
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment