Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8981167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:15:58+00:00 2026-06-15T20:15:58+00:00

I have a database with a table categories which has a unique key on

  • 0

I have a database with a table categories which has a unique key on item_id and user_id. When I’m adding new categories in my controller it using:

$category = new Model_Category();
$category->item_id = $item_id;
$category->user_id = $user_id;
$category->save();

Kohana 3.2 returns a “Duplicate entry ‘1-3’ for key” error. Is it better practice to wrap it in a try/catch or would it be better to check whether the unique key already exists before trying to add it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:15:59+00:00Added an answer on June 15, 2026 at 8:15 pm

    I would advice on a try catch, since it uses one less query to check for the duplicate key, however that might limit the amount of information you can display to the user since im not sure if the exception contains the actual column that violates the key, i think its just a generic error so if you want to actually check which of the two columns gives the error you might wanna use a query before that. Hope it helps. FYI i use try catch most of the time, its cleaner and easy to log errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database which has a table with an XML column. The XML
I have product_details table which belongs to categories. product_details has fields like id, name,
I have a Database with a category table using the Nested Approach in MySql.
I have a database table named Categories . I want to create a form
I have a database table with some rows that I want to fetch using
I have one database table which contains 8 columns. One of the columns is
I have a database table using an enum. This is already working with hibernate
I have Product and Category tables in database. One product can have many categories.
I have two tables in my database - Category and Food. Food has idCategory.
I have a Table for categories , which stores Hierarchical Data in the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.