如何自定义 joomla db sql 错误消息以及如何防止重复条目
我的演出时间表包含以下字段,
id,名称,演出时间,其中id是一个int类型自动递增字段(pK)。 showtime时间类型唯一字段。
当我尝试将 showtime(重复值)添加到 showtime 字段($row->store())时,它显示以下 joomla 错误消息。(我使用 $row->getError()方法)
TableShowTime: :store failed
Duplicate entry '10:30:00' for key 'showtime' SQL=INSERT INTO `jos_myextension_showtime` (`id`,`name`) VALUES ('0','evening')
我想知道有什么方法可以只显示数据库错误消息而不显示sql查询。 我有一个想法在插入之前使用查询检查重复值,这是一个很好的做法吗?请帮助。
my showtime table contains following fields,
id, name, showtime where id is a int type auto-increment field(pK). showtime time type unique field .
when I try to add a showtime(duplicate value) to showtime field($row->store()) it shows the following joomla error message.(I used $row->getError() method)
TableShowTime: :store failed
Duplicate entry '10:30:00' for key 'showtime' SQL=INSERT INTO `jos_myextension_showtime` (`id`,`name`) VALUES ('0','evening')
I want to know is there any way to show only the db error message without showing sql query.
I have an idea to check the duplicate values using a query before insert, is it a good practice? Plz Help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果您不想显示查询,那么您也不应该显示错误消息的其他部分(不要告诉用户您正在尝试插入重复的键)。对此的简单修复可能是这样的:
如果这是自定义组件,您还可以修改表类来自定义这些错误消息,甚至根据错误号显示不同的错误消息。
我希望它有帮助!
I think that if you don't want to display the query, then you shouldn't show the other part of the error message neither (don't tell the user you're trying to insert a duplicate key). A simple fix to this might be something like this:
If this is a custom component, you could also modify your table class to customize these error message, or even show distinct error messages depending on the error number.
I hope it helped!