在codeigniter中执行插入查询后的空白页

时间:2017-05-02 11:14:35

标签: php mysql codeigniter codeigniter-2 codeigniter-3

执行以下查询后,codeigniter显示空白页面,我认为插入查询中存在语法错误,也无法打印查询。请帮忙

我的模型代码如下:

function add_new_user($email,$password,$username)
{

    $sqls="INSERT INTO pr_users (username,userpass,email,departmentid,userroleid,managerid,userlevel,branchid,is_global,registrationtime,timemodified,modifierid,status,deleted,temppass,temppassvalidtill,lastlogin,lastrefresh,lastloginip,if_online,pfield) values ('".$email."','".65e1b655a6d6f4cbed20554d3b52521a743afdc0."','".$email."','".1."','".4."','".10."','".4."','".2."','".0."','".0."','".1491557947."','".1."','".1."','".0."','".."','".0."','".1492084067."','".1492084083."','".::1."','".0."','".unfold983$."')";
    $query=$this->db->query($sqls);

    $result = $this->db->last_query();  
    return $result;

}

3 个答案:

答案 0 :(得分:6)

试试这个

function add_new_user($email,$password,$username)
{
    $sqls="INSERT INTO pr_users (username,userpass,email,departmentid,userroleid,managerid,userlevel,branchid,is_global,registrationtime,timemodified,modifierid,status,deleted,temppass,temppassvalidtill,lastlogin,lastrefresh,lastloginip,if_online,pfield) values ('$email','65e1b655a6d6f4cbed20554d3b52521a743afdc0','$email','1','4','10','4','2','0','0','1491557947','1','1','0','','0','1492084067','1492084083','1','0','unfold983$')";
    $query=$this->db->query($sqls);

    if ($this->db->affected_rows() > 0) {
        echo "Success";
        # return TRUE;
    } 
    else {
        echo "failed";
        # return FALSE;
    }

}
  

注意:确保在index.php(在root中)环境development

define('ENVIRONMENT', 'development'); # line 21

以及强烈推荐使用Codeigniter Query Builder Class

答案 1 :(得分:1)

替换行:

$this->db->last_query();  

使用:

$result = $this->db->last_query();  
return $result;

答案 2 :(得分:1)

重写你的插入语句,如下所示: 检查你的最后一个参数。在我看来,你需要逃避'$'

`$sqls="INSERT INTO pr_users  (username,userpass,email,departmentid,userroleid,managerid,userlevel,branchid,is_global,registrationtime,timemodified,modifierid,status,deleted,temppass,temppassvalidtill,lastlogin,lastrefresh,lastloginip,if_online,pfield) values ('".$email."','65e1b655a6d6f4cbed20554d3b52521a743afdc0','".$email."','1','4','10','4','2','0','0','1491557947','1','1','0','','0','1492084067','1492084083','::1','10','unfold983\$')";`