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

时间:2022-09-07 15:46:02

Ive been learning codeigniter and I like their database methods. However I would prefer to write my own SQL queries. When I try to write a manual query it results in a codeigniter error.

我一直在学习codeigniter,我喜欢他们的数据库方法。但是我更喜欢自己编写SQL查询。当我尝试编写一个手动查询时,它会导致一个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. Or run my own sql queries alongside CodeIgniter's database class?

是否可以禁用Codeigniter数据库方法中的构建,并执行我自己的sql查询。或者在CodeIgniter的数据库类旁边运行我自己的sql查询?

If yes, how would I go about configuring this?

如果是,我该如何配置它?

Thanks in advance

谢谢提前

3 个解决方案

#1


4  

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;
}

#2


0  

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

$ this - > db - >查询(“从your_table selec *”);

you can use like this your core query ...

你可以像这样使用你的核心查询……

#3


-2  

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);

$sql .= " where $ _clause = ?";

`

#1


4  

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;
}

#2


0  

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

$ this - > db - >查询(“从your_table selec *”);

you can use like this your core query ...

你可以像这样使用你的核心查询……

#3


-2  

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);

$sql .= " where $ _clause = ?";

`