Question

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.

Was it helpful?

Solution

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 ( $row>getError() ) {
   echo "Could not store [...]";
}

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top