Mysql Duplicate Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more check duplicate entry mysql php about Stack Overflow the company Business Learn more about hiring developers or posting ads
Mysql Duplicate Entry Error Code
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack
Mysql Error 1062 Duplicate Entry For Key Primary
Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Display error message in php for MYSQL duplicate error up vote 1
Mysql Error Codes
down vote favorite I am using UNIQUE Constraint in my table for two columns to prevent duplicate rows. If I try to insert a row with the same 2 columns I get A Database Error Occurred Error Number: 1062 Duplicate entry '62-88' for key 'subscription' INSERT INTO subscriptions (user_id, subscribed_to, date) VALUES ('62', '88', '2011-07-11 19:15:13') Filename: C:\wamp\www\mysite\system\database\DB_driver.php Line Number: 330 How can I return a php error, e..g mysql error code 1062 Already subscribed! instead of displaying the mysql error? php mysql mysql-error-1062 share|improve this question edited May 24 '12 at 13:02 leeand00 8,7051988200 asked Jul 10 '11 at 16:21 CyberJunkie 5,3702794151 possible duplicate of Handle error for duplicate entries - PHP MySQL –Ben Sep 23 '15 at 12:19 add a comment| 4 Answers 4 active oldest votes up vote 4 down vote accepted Call mysql_errno() after your mysql_query() and check for 1062. Note: It's a more common/intuitive solution to query the database first. See answer by Manocho. share|improve this answer answered Jul 10 '11 at 16:26 Jason McCreary 46.6k1480128 1 +1: The fewer trips between the database & the application, the better. –OMG Ponies Jul 10 '11 at 16:47 Thanks for the suggestion! I'm using an MVC pattern. If I understood correctly, I add mysql_errno() after my insert query (in my model) and that should return 1062? Then I would use if ($query == 1062) display error? –CyberJunkie Jul 10 '11 at 17:52 Yes. You could put it in your Model. But I'd argue this is business logic and it may be better served in your Controller. Note, check if mysql_errno() returns 1062, not the query. –Jason McCreary Jul
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the mysql 23000 workings and policies of this site About Us Learn more about Stack mysql error 1032 Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs mysql_code_duplicate_key Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; http://stackoverflow.com/questions/6642244/display-error-message-in-php-for-mysql-duplicate-error it only takes a minute: Sign up Mysql insert query returns ERROR 1062 (23000): Duplicate entry '2147483647' for key 'PRIMARY' up vote 0 down vote favorite I've noticed an error during an insert query in my database. mysql> insert into users (name) values ('Gepp'); returned: ERROR 1062 (23000): Duplicate entry '2147483647' for key 'PRIMARY' It's the first time I http://stackoverflow.com/questions/18643648/mysql-insert-query-returns-error-1062-23000-duplicate-entry-2147483647-for get this error maybe this suggests that some kind of limit has been reached. Anyway I've checked in other posts complaining for the same error and found out that triggers may be the problem. Unfortunately it's not the case: mysql> SHOW triggers; Empty set (0.00 sec) EDIT The structure of my users table is shown below: > *************************** 1. row *************************** Field: uid Type: int(11) Null: NO Key: PRI Default: NULL Extra: auto_increment *************************** 2. row *************************** Field: name Type: varchar(50) Null: NO Key: Default: NULL Extra: *************************** 3. row *************************** Field: email Type: varchar(100) Null: NO Key: UNI Default: NULL Extra: *************************** 4. row *************************** Field: encrypted_password Type: varchar(80) Null: NO Key: Default: NULL Extra: *************************** 5. row *************************** Field: salt Type: varchar(10) Null: NO Key: Default: NULL Extra: *************************** 6. row *************************** Field: descrizione Type: varchar(600) Null: YES Key: Default: NULL Extra: *************************** 7. row *************************** Field: motto Type: varchar(100) Null: NO Key: Default: Extra: *************************** 8. row *************************** Field: status Type: varchar(100) Null: NO Key: Default: Hey new gambler! Share your thoughts! Extra:
Connectors More MySQL.com Downloads Developer Zone Section Menu: Documentation Home MySQL 5.7 Reference Manual Preface and Legal Notices General Information Installing and Upgrading MySQL http://dev.mysql.com/doc/en/error-messages-server.html Using MySQL as a Document Store Tutorial MySQL Programs MySQL Server http://www.ducea.com/2008/02/13/mysql-skip-duplicate-replication-errors/ Administration Security Backup and Recovery Optimization Language Structure Globalization Data Types Functions and Operators SQL Statement Syntax The InnoDB Storage Engine Alternative Storage Engines High Availability and Scalability Replication MySQL Cluster NDB 7.5 Partitioning Stored Programs and Views INFORMATION_SCHEMA Tables MySQL Performance Schema mysql error MySQL sys Schema Connectors and APIs Extending MySQL MySQL Enterprise Edition MySQL Workbench MySQL 5.7 Frequently Asked Questions Errors, Error Codes, and Common Problems Sources of Error Information Types of Error Values Server Error Codes and Messages Client Error Codes and Messages Problems and Common Errors How to Determine What Is Causing a Problem Common mysql error code Errors When Using MySQL Programs Access denied Can't connect to [local] MySQL server Lost connection to MySQL server Client does not support authentication protocol Password Fails When Entered Interactively Host 'host_name' is blocked Too many connections Out of memory MySQL server has gone away Packet Too Large Communication Errors and Aborted Connections The table is full Can't create/write to file Commands out of sync Ignoring user Table 'tbl_name' doesn't exist Can't initialize character set File Not Found and Similar Errors Table-Corruption Issues Administration-Related Issues Problems with File Permissions How to Reset the Root Password What to Do If MySQL Keeps Crashing How MySQL Handles a Full Disk Where MySQL Stores Temporary Files How to Protect or Change the MySQL Unix Socket File Time Zone Problems Query-Related Issues Case Sensitivity in String Searches Problems Using DATE Columns Problems with NULL Values Problems with Column Aliases Rollback Failure for Nontransactional Tables Deleting Rows from Related Tables Solving Problems with No Matching Rows Problems with Floating-Poin
This happens in order for us to be able to identify the problem and fix it, and keep the data consistent with the mater that has sent the query. You can skip such errors, even if this is not recommended, as long as you know really well what are those queries and why they are failing, etc. For example you can skip just one query that is hanging the slave using: 1 mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE; There might be cases where you will want to skip more queries. For example you might want to skip all duplicate errors you might be getting (output from show slave status;): 1 "1062 | Error 'Duplicate entry 'xyz' for key 1' on query. Default database: 'db'. Query: 'INSERT INTO ..." If you are sure that skipping those errors will not bring your slave inconsistent and you want to skip them ALL, you would add to your my.cnf: 1 slave-skip-errors = 1062 As shown above in my example 1062 is the error you would want to skip, and from here we have: _ Error: 1062 SQLSTATE: 23000 (ER_DUP_ENTRY) Message: Duplicate entry ‘%s’ for key %d_ You can skip also other type of errors, but again don’t do this unless you understand very well what those queries are and what impact they have on your data: 1 slave-skip-errors=[err_code1,err_code2,...|all] and for the error codes you can see them all here … (you will see them in your _show slave statu_s; also). Posted by Marius Ducea Feb 13th, 2008 posted in: tips & tricks tagged with: mysql, tips Tweet « Linux Tips: find all files of a particular size Increase PHP memory limit » Comments Please enable JavaScript to view the comments powered by Disqus. About Me My name is Marius Ducea. I am an experienced Infrastructure Developer based in the SF Bay Area