我有以下声明,我可以在MySQL中执行:
SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT'MAX(IF(Name = ''', Name, ''', Name, NULL)) AS `', Name, '`') INTO @sql
from Contact_Types;
SET @sql = CONCAT('SELECT c.First_Name, ', @sql, ' from Contacts c
left join Contacts_Contact_Types cct
on c.Contact_Id = cct.Contact_Id
left join Contact_Types ct
on cct.Contact_Type_Id = ct.Contact_Type_Id
group by c.Contact_Id');
PREPARE statement FROM @sql;
EXECUTE statement;
DEALLOCATE PREPARE statement;
这个准备好的声明允许我动态检索"联系人类型"与联系人相关联。如何在CodeIgniter中执行此预准备语句并检索结果?我在CI文档中找不到任何相关内容。
尝试执行以下操作时收到SQL语法错误:
$this->db->query("PREPARE statement FROM @sql; EXECUTE statement; DEALLOCATE PREPARE statement;");
感谢您提供的任何帮助!