Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Functions in Codeigniter Data

Using codeigniter I'm trying to insert a row into my database, but I want the data in the row to be generated by MySQL. What is the proper way of doing it?

$data['my_id'] = 'UUID()';
$db->insert('my_table',$data);

Obviously the above won't work, but how can I make it function?

EDIT: Theoretically this is what the above should produce:

INSERT INTO my_table (my_id) VALUES (UUID());

Naturally my actually query isn't that simple, but that should get the point across.

like image 639
Aram Papazian Avatar asked Mar 27 '26 13:03

Aram Papazian


1 Answers

you can use $this->db->set('my_id', 'UUID()', FALSE);

For passing mltiple params,

$data = array(.....) //add the params.
$this->db->set('my_id', 'UUID()', FALSE);
$this->db->insert('my_table',$data);
like image 198
itachi Avatar answered Mar 30 '26 02:03

itachi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!