使用 CodeIgniter Active Record 类按域名扩展名排序
$extension = “SUBSTRING_INDEX(domain_name, ‘.’, -1)”;
$this->db->order_by($extension, “asc”);
它说: 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 44 行的“asc LIMIT 50”附近使用的正确语法,
但是当我没有使用 $this->db->order_by Active Record 类时它可以工作 比如这个: $this->db->query(“SELECT * FROM 域 ORDER BY SUBSTRING_INDEX(domain_name, '.', -1)”);
任何人请帮助我。谢谢。
$extension = “SUBSTRING_INDEX(domain_name, ‘.’, -1)”;
$this->db->order_by($extension, “asc”);
It says:
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 ‘asc LIMIT 50’ at line 44
But its working when I didn’t used the $this->db->order_by Active Record Class
such as this one:
$this->db->query(“SELECT * FROM domain ORDER BY SUBSTRING_INDEX(domain_name, ‘.’, -1)”);
Anyone please help me. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您需要像这样扩展数据库活动记录库: http://codeigniter.com/wiki /Extending_Database_Drivers/
将另一个参数(例如 $escape=null)添加到 order_by,并使用它来防止 _protect_identifiers 在您的函数中运行。这将允许您以与现在使用 select 和 where 相同的方式使用未转义的 order by 。
I believe you'd need to extend the database active record library like this: http://codeigniter.com/wiki/Extending_Database_Drivers/
Add another argument like $escape=null to the order_by, and use it to prevent _protect_identifiers from running in your function. This would let you use an unescaped order by in the same way that select and where can be used now.
自从:
$extension = “SUBSTRING_INDEX(域名, '.', -1)”;
$this->db->order_by($extension, “asc”);
结果为:
SUBSTRING_INDEX(domain_name, `'`.`'`, `-1)`
我编辑:
系统/数据库/驱动程序/mysql/mysql_driver.php
通过改变:
var $_escape_char = '`';
到
var $_escape_char = '';
Since:
$extension = “SUBSTRING_INDEX(domain_name, ‘.’, -1)”;
$this->db->order_by($extension, “asc”);
Result to:
SUBSTRING_INDEX(domain_name, `'`.`'`, `-1)`
I edit:
system/database/drivers/mysql/mysql_driver.php
by changing:
var $_escape_char = '`';
to
var $_escape_char = '';