Doubt in insert, update and delete with Framework CodeIgniter?

2

I have a question regarding the insertion, change and removal of the records in the MySql database. For example, imagine a table of notes where all the information in this note, such as supplier data, carrier data and taxes to be collected, is entered. And we also have a nota_itens table, where the items in this note will be inserted. Well, in structured PHP, I would do the following: First I would do an INSERT to register the data of the note table and then I would do another INSERT to register the data of the nota_notes table with the last id of the note table in the nota_notes table referencing then the two tables. My question is as follows, in CodeIgniter Framework is there any mechanism or function that does this automatically? Or do I have to implement the same idea of structured PHP? I hope to have been clear in my doubt and thank you!

    
asked by anonymous 23.03.2015 / 18:57

3 answers

0

I think you do not have to, you'll have to do both inserts, it gets even easier using the functions passed by Andrew Maxwell and GWER

    
24.03.2015 / 18:34
0

You have a colleague, you have a database function that does this procedure $this->db->insert_id() , it takes the last id registered in the database. Vlw

    
23.03.2015 / 22:52
0

Try to use last_insert_id() ;

The MySQL function last_insert_id() returns the last integer created for an auto_increment column of a table. This integer is available in the memory cache that MySQL uses to store the auto_increment column, thus generating the string.

See here: link

PDO: link

    
23.03.2015 / 21:54