Random DB Error - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Random DB Error (/showthread.php?tid=11074) |
Random DB Error - El Forum - 08-25-2008 [eluser]Jay Logan[/eluser] My site lets users add there school to a database. It works about 90% of the time but sometimes, users are given this error: Code: A Database Error Occurred Apparently, the system sometimes gives schools the same ID. I wondering if you guys could take a look at the code I'm using and see any obvious errors. My base model contains: Code: function unique_id() My school model contains: Code: function insert($values) Thanks for any help you can give me. Random DB Error - El Forum - 08-25-2008 [eluser]steelaz[/eluser] 2147483647 is max for MySQL INT. I would suggest changing the field type to BIGINT. Random DB Error - El Forum - 08-25-2008 [eluser]Jay Logan[/eluser] Yes, it has always been set to BIGINT(11). Thanks for reply. Random DB Error - El Forum - 08-25-2008 [eluser]steelaz[/eluser] I don't think it's a coincidence that your error is showing exactly '2147483647'. Couple suggestions: Double check all your field types. If you're not using negative integer values, make them 'unsigned'. Remove (11) next to BIGINT. Random DB Error - El Forum - 08-25-2008 [eluser]Jay Logan[/eluser] I have made your changes. Though I don't think it works properly. I tried to add another school and got this error: Code: A Database Error Occurred I hit the refresh button, and got this error: Code: A Database Error Occurred So it appears to be grabbing random ID numbers without checking to see if that ID already exists in the DB. Random DB Error - El Forum - 08-25-2008 [eluser]steelaz[/eluser] Do you currently have a function to check for existing IDs? If no, your insert function should be modified to something like this: Code: function insert($values) Random DB Error - El Forum - 08-25-2008 [eluser]Jay Logan[/eluser] I've implemented the code and added 4 schools without any problems. I will have users test it out for a while but it seems like it should work. I can't thank you enough for this. |