错误号码:1054 Unknow Column Codeigniter

时间:2017-02-16 04:57:00

标签: php mysql codeigniter

我有一个代码可以从链接在一起的表中检索数据。这是代码

public function getdatamentor($key)
{
    $this->db->select('iduser');
    $this->db->where('idtraining', $key, false);
    $hasil= $this->db->get('ttraining');
    $this->getNama($hasil->result());
}

public function getNama($key)
{
    $this->db->select('nama');
    $this->db->where('iduser', $key, false);
    $hasil = $this->db->get('tmember');
    return $hasil;
}

但它返回错误

Error Number: 1054

Unknown column 'TWO00000' in 'where clause'

SELECT `iduser` FROM `ttraining` WHERE idtraining = TWO00000

Filename: C:/xampp/htdocs/gofastforex/system/database/DB_driver.php

Line Number: 691

感谢您的帮助

3 个答案:

答案 0 :(得分:1)

因为在函数第三个参数中使用set public int totalAccidents(){ int total = 0; for(int i=0; i<accidents.length; i++){ for(int j=0; j<accidents[0].length; j++){ total += accidents[i][j]; } } return total; } public int mostAccidents(){ int sum = 0; int max = 0; for (int i=0;i<24;i++){ for(int j=0; j<accidents.length; j++){ sum += accidents[j][i]; } if (sum> max) max = sum; } return max; } public void printArray(){ for(int j=0; j<accidents.length; j++){ for(int k=0; k<accidents[0].length; k++){ System.out.print(accidents[j][k]+" "); } System.out.println(); } } }

false

如果设置为false且value为string,则不保护值(Lib不能自动添加单引号)。并且不受保护,值将被视为字段名称。因此,您应该删除或设置$this->db->where('idtraining', $key, false);

true

转换为SQL:

$this->db->where('idtraining', $key);

答案 1 :(得分:1)

where方法中的第三个参数用于转义

$this->db->where('idtraining', $key, true); //

最好在这里阅读

https://www.codeigniter.com/userguide3/database/query_builder.html?highlight=where%20cla#CI_DB_query_builder::where

答案 2 :(得分:0)

尝试下面

public function getNama($key)
{
    $this->db->select('nama');
    $this->db->where('iduser',"$key");
    $hasil = $this->db->get('tmember');
    return $hasil;
}
相关问题