Welcome Guest, Not a member yet? Register   Sign In
Random DB Error
#1

[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.


Messages In This Thread
Random DB Error - by El Forum - 08-25-2008, 09:04 AM
Random DB Error - by El Forum - 08-25-2008, 11:04 AM
Random DB Error - by El Forum - 08-25-2008, 12:09 PM
Random DB Error - by El Forum - 08-25-2008, 12:40 PM
Random DB Error - by El Forum - 08-25-2008, 12:53 PM
Random DB Error - by El Forum - 08-25-2008, 01:20 PM
Random DB Error - by El Forum - 08-25-2008, 01:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB