简体   繁体   English

是否可以在CodeIgniter中使用手动SQL查询?

[英]Is it possible to use manual SQL queries in CodeIgniter?

Ive been learning codeigniter and I like their database methods. 我一直在学习codeigniter,我喜欢他们的数据库方法。 However I would prefer to write my own SQL queries. 但是我更喜欢编写自己的SQL查询。 When I try to write a manual query it results in a codeigniter error. 当我尝试编写手动查询时,会导致codeigniter错误。

Ive searched around if it is possible however I cant find much info on the subject. 我四处搜索是否有可能但是我无法找到关于这个主题的更多信息。 The closes Ive come to an answer was this . 关闭我得到的答案就是这个

Question

Is it possible to disable the build in Codeigniter database methods, and perform my own sql queries. 是否可以禁用Codeigniter数据库方法中的构建,并执行我自己的SQL查询。 Or run my own sql queries alongside CodeIgniter's database class? 或者在CodeIgniter的数据库类旁边运行我自己的SQL查询?

If yes, how would I go about configuring this? 如果是,我将如何配置?

Thanks in advance 提前致谢

From https://www.codeigniter.com/userguide3/database/results.html , you can use query method from db library. https://www.codeigniter.com/userguide3/database/results.html ,您可以使用db库中的查询方法。

$query = $this->db->query("YOUR QUERY");

foreach ($query->result() as $row)
{
        echo $row->title;
        echo $row->name;
        echo $row->body;
}

$this->db->query('selec * from your_table'); $ this-> db-> query('selec * from your_table');

you can use like this your core query ... 你可以像这样用你的核心查询......

This may help you out 这可能会帮到你

` `

$sql = "select model,varient,(select color from mtbl_colors where
        mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles";

$sql .= " where $where_clause = ?"; $result = $this->db->query($sql, $where_value);

` `

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

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