我如何在codeigniter中编写这个MYSQL语句?

时间:2016-03-29 17:57:38

标签: java jquery mysql codeigniter

如何在codeigniter中编写此MYSQL语句?

SELECT *, (UserPassword = $pass) AS UserPasswordMatch FROM all_users WHERE UserName = $Username

2 个答案:

答案 0 :(得分:1)

你有2个选择 作为普通查询

$this->db->query("SELECT *, (UserPassword = $pass) AS UserPasswordMatch FROM all_users WHERE UserName = $Username");
return $this->db->get()->result();

使用CI的活动记录

$this->db->select('*')->from('all_users')->where(array('UserPassword' => $pass, 'UserName' => $Username));
return $this->db->get()->result();

答案 1 :(得分:0)

希望这会有所帮助:

第一个选项 without using active records

<?php
$q = $this->db->query("SELECT * FROM all_users WHERE UserName = '$Username' AND UserPassword = '$pass'");
return $this->db->get()->result();
?>

第二个选项使用active records

<?php
$this->db->select('*');
$this->db->from('all_users');
$this->db->where('UserName', $Username);
$this->db->where('UserPassword', $pass);
return $this->db->get()->result();
?>