首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >codeigniter选择*,*错误自动生成

codeigniter选择*,*错误自动生成
EN

Stack Overflow用户
提问于 2018-05-31 01:22:35
回答 1查看 0关注 0票数 0

我装了这个函数,它的工作原理几乎总是无处不在,开始产生这个错误,有人可以帮助我吗?

代码语言:javascript
复制
 function busca_um($id = NULL, $usuario = NULL, $email = null) 
 {


        if (isset($id)) {
            $this->db->where('usuario_id', $id);
        }
        if (isset($usuario)) {
            $this->db->where('usuario', $usuario);
        }
        if (isset($email)) {
            $this->db->where('email', $email);
        }

        $query = $this->db->get('tb_usuario');


        if (sizeof($query) > 0) {
            $result = $query->result();
            return $result[0];
        } else {
            return null;
        }
    }

从我的sql生成这个错误

SELECT *,* FROM tb_usuarioWHERE usuario='xxxx'

这个错误我不能查找选择*,*

有人知道吗?

EN

回答 1

Stack Overflow用户

发布于 2018-05-31 11:20:52

你的模型的方法busca_um应该是这样的:

代码语言:javascript
复制
function busca_um($id = NULL, $usuario = NULL, $email = null) 
  {
    if (! empty($id)) 
    {
        $this->db->where('usuario_id', $id);
    }
    if (! empty($usuario)) 
    {
        $this->db->where('usuario', $usuario);
    }
    if (! empty($email))
    {
        $this->db->where('email', $email);
    }

    $query = $this->db->get('tb_usuario');


    if ($query->num_rows() > 0) 
    {
       return $query->row();
       /* you can also use the same as above
          $result = $query->result();
          return $result[0];
       */
    } 
    else 
    {
        return null;
    }
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100004639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档