uuid |
hii, how to set uuid as primary key in ci4 ??
database used mysql / postgresql
This may help you understand how MySQL uses the UUID.
MySQLTutorial -> MySQL UUID Smackdown: UUID vs. INT for Primary Key What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-11-2023, 10:19 PM)InsiteFX Wrote: This may help you understand how MySQL uses the UUID. oke thank you for the info, but what is the best pratic if i want to integrated uuid as primary key in my database/ model should i custome in callback model before insert?
NOTE: That the MySQL UUID only works with MySQL 8+
For any other version you will need to roll your own methods to handle UUID. Ok, I found this one on MySQL 5.7 in their Blog Archive. MySQL Blog Archive -> Storing UUID Values in MySQL Tables What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-11-2023, 10:46 PM)InsiteFX Wrote: NOTE: That the MySQL UUID only works with MySQL 8+ oke thank you
05-13-2023, 04:17 AM
(This post was last modified: 05-13-2023, 04:25 AM by gosocial2. Edit Reason: Added forgotten )
Here's an implementation (also used by CodeIgniter Wizard):
In the database table set the PK field as char(36). E.g. let's assume we have a table named cms_pages whose primary key is a field named uuid and is of type char(36) Create a trait for UUID generation: PHP Code: <?php Example model using the trait: PHP Code: <?php In a custom helper function file (e.g. go_helper.php): PHP Code: if (!function_exists('newUUID')) { CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5) |
Welcome Guest, Not a member yet? Register Sign In |