[nycphp-talk] Inserting duplicate SQL primary keys
Rahmin Pavlovic
rahmin at insite-out.com
Thu Jul 26 14:00:37 EDT 2007
Cliff Hirsch wrote:
> Apologies if this should be in the MySQL list, but it does seem to be a
> PHP-level issue.
>
> While testing, I just did a page refresh, which caused this action to be
> repeated:
>
> $query_string = "INSERT INTO task_category (task_id, category_id) VALUES
> ($taskId, $categoryId)";
> $this->dbManager->DbQuery($query_string);
>
Depending on your versioning and app-flow, you can either do a SELECT first
to see if your key exists, or something like:
INSERT INTO table(primaryKey,someData) VALUES (1234, 'test')
ON DUPLICATE KEY UPDATE someData = VALUES('test');
More information about the talk
mailing list