简体   繁体   English

将MySQL查询转换为Codeigniter Active Records

[英]convert following MySQL query into Codeigniter Active Records

I`m new to codeigniter and I like to convert following MySQL queries into Codeigniter Active Record Queries. 我是codeigniter的新手,我喜欢将以下MySQL查询转换为Codeigniter Active Record Queries。

'SELECT name, address, detail, status, startdate, FROM job_step WHERE username = '$_SESSION[username]'  and 'status'===0'

PS- job_step table consists of several columns, but I only need few not the entire table, addition to that information should filter according to session name and status (TINYINT which has 1 and 0). PS-job_step表由几列组成,但我只需要很少的几个而不是整个表,除了该信息之外,还应根据会话名称和状态(TINYINT有1和0)进行过滤。

$this->db->select('name, address, detail, status, startdate')
              ->from('job_step')
              ->where(array('username' => $_SESSION['username'], 'status' => 0))
              ->get()
              ->result();

This will get you an object. 这会给你一个对象。 If you want array just change last line to ->result_array(); 如果你想要数组只需将最后一行更改为->result_array();

You can write the above query as: 您可以将以上查询编写为:

$this->db->select('name, address, detail, status, startdate');
$this->db->where('username',$_SESSION['username']);
$this->db->where('status','0');
$rset=$this->db->get('job_step');
$result=$rset->result();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM