对于遗留项目,我希望使用CodeIgniter执行此查询:
DELIMITER $$
CREATE FUNCTION `getCustomerFullName`(intCustomerID INT)
RETURNS varchar(100) CHARSET latin1
return CONCAT(
(SELECT FirstName FROM Customer WHERE CustomerID = intCustomerID),
' ',
(SELECT LastName FROM Customer WHERE CustomerID = intCustomerID))$$
DELIMITER ;
当我尝试使用
$this->db->query()
时,会出现以下错误:You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near
'DELIMITER $$ CREATE FUNCTION `getCustomerFullName`(intCustomerID INT) RETURNS '
at line 1
如何使用CodeIgniter执行这种“多行”查询?
最佳答案
问题出在查询中,而不是CodeIgniter。在函数中使用常规分隔符:
DELIMITER $$
CREATE FUNCTION `getCustomerFullName`(intCustomerID INT)
RETURNS varchar(100) CHARSET latin1
return CONCAT(
(SELECT FirstName FROM Customer WHERE CustomerID = intCustomerID),
' ',
(SELECT LastName FROM Customer WHERE CustomerID = intCustomerID));
$$
DELIMITER ;