gpt4 book ai didi

MySQL 函数和 CodeIgniter Active Record

转载 作者:行者123 更新时间:2023-11-29 01:24:14 25 4
gpt4 key购买 nike

CodeIgniter Active Record 非常简单、文档齐全且功能强大。但是当我尝试插入 MySQL 内置函数 CONCATNOWGROUP_CONCATDATEDIFFTRIM 等或我的自定义函数出现错误。下面的代码工作正常...

$result = $this->db->select('p.first_name, p.last_name, p.mobile_number, p.email_address')->from('profile p')->get()->result();

但是当我想联系 first_namelast_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 函数?希望我说清楚了。提前致谢。

最佳答案

因为我不知道你的确切错误:

来自用户指南:

$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

$result = $this->db->select('CONCAT(p.first_name, " ", p.last_name) fullname, p.mobile_number, p.email_address', FALSE)->from('profile p')->get()->result();

关于MySQL 函数和 CodeIgniter Active Record,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6992705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com