CodeIgniter活動記錄很容易,有據可查,功能強大。但是當我嘗試插入函數CONCAT
,NOW
,GROUP_CONCAT
,, DATEDIFF
,TRIM
等內建的MySQL或我的自定義函數時,它會給出錯誤。下面的代碼工作正常...MySQL函數和CodeIgniter活動記錄
$result = $this->db->select('p.first_name, p.last_name, p.mobile_number, p.email_address')->from('profile p')->get()->result();
但是,當我想聯繫first_name
和last_name
和使用MySQL CONCAT
功能是這樣的...
$result = $this->db->select('CONCAT(p.first_name, " ", p.last_name) fullname, p.mobile_number, p.email_address')->from('profile p')->get()->result();
它顯示數據庫錯誤
A Database Error Occurred
Error Number: 1064
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 '", `p`.`last_name)` fullname, `p`.`mobile_number`, `p`.`email_address` FROM (`pr' at line 1
SELECT CONCAT(p.first_name, `"` ", `p`.`last_name)` fullname, `p`.`mobile_number`, `p`.`email_address` FROM (`profile` p)
Filename: D:\xampp\htdocs\example\system\database\DB_driver.php
Line Number: 330
有什麼方法可以在CodeIgniter Active Record中插入MySQL函數嗎?希望我清楚。提前致謝。
可能重複:[CONCAT()在選擇欄列表功能(http://stackoverflow.com/q/4519838)和示例:CONCAT在PHP笨( http://stackoverflow.com/q/4623958)。 – Apostle