使用 CodeIgniter Active Record 类按域名扩展名排序

发布于 2024-08-29 00:10:42 字数 390 浏览 4 评论 0原文

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离线来电— 2024-09-05 00:10:42

我相信您需要像这样扩展数据库活动记录库: 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.

笑看君怀她人 2024-09-05 00:10:42

自从:
$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 = '';

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文