gpt4 book ai didi

mysql - 查询生成器 - codeigniter

转载 作者:行者123 更新时间:2023-11-29 17:56:10 24 4
gpt4 key购买 nike

我在构建使用三个表的查询时遇到问题。

如果我将查询写为:

$query = "select domains.ID, domains.Name, domains.IP, 
database_info.DB_Name, database_info.DB_User, database_info.DB_Pass,
ftp.FTP_User, ftp.FTP_Pass from domains
left join database_info on domains.ID = database_info.Domain_ID
left join ftp on domains.ID = ftp.Domain_ID
where domains.ID = $ID";

$query = $this->db->get();
if($query->num_rows()>0){
return $query->result();
}

我收到错误号 1096 没有使用表 SELECT *但是我使用查询生成器编写查询:

       $this->db->select('domains.ID','domains.Name','domains.IP',
'database_info.DB_Name','database_info.DB_User',
'database_info.DB_Pass','ftp.FTP_User','ftp.FTP_Pass');
$this->db->from('domains');
$this->db->join('database_info','domains.ID =
database_info.Domain_ID', 'left');
$this->db->join('ftp','domains.ID = ftp.Domain_ID','left');
$this->db->where('domains.ID',$ID);
$query = $this->db->get();
if($query->num_rows()>0){
return $query->result();
}

查询运行但仅返回domains.ID接受想法和建议

最佳答案

试试这个

$query = $this->db
->select('domains.ID,domains.Name,domains.IP, database_info.DB_Name,database_info.DB_User,database_info.DB_Pass,ftp.FTP_User,ftp.FTP_Pass')
->from('domains')
->join('database_info','domains.ID = database_info.Domain_ID', 'left')
->join('ftp','domains.ID = ftp.Domain_ID','left')
->where('domains.ID',$ID)
->get();
if($query->num_rows()>0)
{
return $query->result();
}

重点在于您的 select 语句 - 查询生成器只接受整个 select 语句的一个参数,而不是像您那样多

and please for the sake of security - never ever try to execute sql statements without escaping them - CI's query builder will do this per default - but your first example is pretty dangerous and widely open to sql injections

关于mysql - 查询生成器 - codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48804137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com