How to insert UUID in CodeIgniter

Universal Unique Identifier (UUID) in MySQL is used as row identity value (PRIMARY KEY). It is unique in every database, so you can merging records from different databases.

If you are working in CodeIgniter and want to insert UUID as row PRIMARY KEY, use the following sample code to insert UUID into MySQL table. UUID() function generate a 128-bit number which is globally unique in space and time.

//set multiple column values
$data = array(
    
'name' => 'CodexWorld',
    
'email' => 'contact@codexworld.com',
    
'mobile' => '8888888888'
);

//set id column value as UUID
$this->db->set('id''UUID()'FALSE);

//insert all together
$this->db->insert('table_name',$data);

Leave a reply

keyboard_double_arrow_up