在codeigniter php准备语句


Prepared Statement in codeigniter php

SELECT answer into @a from progress where id = 1;
SELECT answer into @b from progress where id = 2;
SELECT answer into @c from progress where id = 3;
SET @query = CONCAT('select ?, ?, ', @c);
PREPARE stmt1 from @query;
EXECUTE stmt1 using @a, @b;

我想用codeigniter模型写一个等价的代码,但是我不知道怎么做。

我的数据库是这样的:

表名:progress

id  label_id  answer
1      1        5
2      2        10
3      3        @a+@b

表名:master

id   label
1      a
2      b
3      c

有谁能建议如何做到这一点吗?

CodeIgniter没有任何内置机制来执行SELECT INTO语句。我也一直在CodeIgniter的一个项目上工作,我目前正在用PDO替换默认的数据库代码(出于某种原因,他们称之为activerecord)。要做到这一点,唯一的方法是在

$query = "SELECT * INTO :table FROM somethingelse";
$query = str_replace(':table' , 'yourtablename', $query);
$this->db->query($query);
//.. rest of your code here