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 9155379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:34:59+00:00 2026-06-17T12:34:59+00:00

I have developed a script using Yii MVC and i have a problem with

  • 0

I have developed a script using Yii MVC and i have a problem with the index keys and criterias.

I want to prevent the insertion of a record that is already stored in the database;

My example, fails to check and tries to add a new record each time.

Why ? And how to do this ?

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '21-/popular/category/1.html' for key 'index_link'. The SQL statement executed was: INSERT INTO `categories` (`server_id`, `website_id`, `slave_category_id`, `link`, `name`, `image`, `videos`, `status`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, :yp7)

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `server_id` int(11) NOT NULL,
  `website_id` int(11) NOT NULL,
  `slave_category_id` int(11) NOT NULL,
  `link` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `image` varchar(255) NOT NULL,
  `videos` int(11) NOT NULL,
  `status` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `index_link` (`website_id`,`link`),
  UNIQUE KEY `index_name` (`website_id`,`name`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=332 ;

the PK is id;
another index, is website_id + link;
another index is website_id + name;

the following code fails to check and prevent the insertion:
1

    $criteria_categories = new CDbCriteria();
                                    $criteria_categories->condition = " `server_id`=':server_id' and `website_id`=':website_id' and `link`=':link' and `name`=':name' ";
                                    $criteria_categories->params = array(
                                        ':server_id' => $model_website->server_id,
                                        ':website_id' => $model_website->id,
                                        ':link' => $matches_url[$value->link][$key2],
                                        ':name' => $matches_url[$value->name][$key2],
                                   );
$record_categories = Categories::model()->find($criteria_categories);
print_r($record_categories);
if (!$record_categories) {
$model_categories = new Categories();
$model_categories->server_id = $model_website->server_id;
$model_categories->website_id = $model_website->id;
$model_categories->slave_category_id = 1; //??
$model_categories->link = $matches_url[$value->link][$key2];
$model_categories->name = $matches_url[$value->name][$key2];
$model_categories->image = $matches_url[$value->image][$key2];
$model_categories->videos = 0;
$model_categories->status = 0;
$model_categories->save();
}
  • 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-17T12:35:00+00:00Added an answer on June 17, 2026 at 12:35 pm
    $criteria_categories->condition = " `server_id`=':server_id' and `website_id`=':website_id' and `link`=':link' and `name`=':name' ";
    

    You have a couple errors going on. One is syntax. If using the parameter binding (which is a good thing to use), you don’t want to quote the parameters.

    That is, write :link instead of ':link'.

    The above condition also does not correctly check for existing records that have either of your two unique keys. Try the following:

    $criteria_categories->addCondition("`server_id`=:server_id AND `website_id` = :website_id
    AND (`link`=:link OR `name` = :name)");
    

    This both quotes correctly and will find the record if either of your two unique keys match, rather than requiring both to match.

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

Sidebar

Related Questions

I have developed a script that receives json data from a php script using
I have developed a Powershell script that needs to be run automatically daily. This
I have developed code on a m-file script in Matlab that communicates with a
I have developed tower of hanoi game in java script. Now, I want to
I have developed a dragable div with an image inside using jquery. The script
I have a news feed that has been developed using PHP, MySQL, and jQuery.
I have developed a recursive FTP-download script, in PHP5, that allows you to select
We have developed web application using c#.net and java script grids are not displaying
I have a custom developed WordPress plugin that is using jQuery 1.4 and for
I have developed application in Netbeans IDE 6.9 Using javafx Script based Application. i

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.