[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
Error Number: 1062
Duplicate entry '2147483647' for key 1
INSERT INTO `schools` (`abbr`, `name`, `city`, `state`, `type`, `host_id`, `id`) VALUES ('RNE', 'Northeast High School', 'Columbia', 'SC', 'M', '4', 'd7d0e5348a4501a8b2f635d47276')
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()
{
$id = uniqid(dechex(rand()), true);
$id = explode('.', $id);
$id[1] = dechex($id[1]);
$id = implode('', $id);
return $id;
}
My school model contains:
Code:
function insert($values)
{
$values['id'] = $this->unique_id();
$this->db->insert('schools', $values);
return $values['id'];
}
Thanks for any help you can give me.