Problem with inserting csv file entries to db - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Problem with inserting csv file entries to db (/showthread.php?tid=73638) |
Problem with inserting csv file entries to db - HarrysR - 05-16-2019 What i'm facing here has kinda confused me. I'm trying to insert some entries parsed from csv file into db. I found the csv library, it works and so far so good. I have the following script in controller: "Products/insert", Code: if ($this->csvimport->get_array($file_path)) { And here's my model: Code: public function insert_product($data){ I've also tried batch_insert but i can't check other tables and return the id. If anyone has ever made it, please feel free to suggest a solution on this.. Thanks in advance... RE: Problem with inserting csv file entries to db - php_rocs - 05-16-2019 @HarrysR, What are you trying to accomplish? Inserting records? Get the id of the created records? Are you getting error messages? If so, what error messages are you receiving? RE: Problem with inserting csv file entries to db - HarrysR - 05-17-2019 (05-16-2019, 08:40 PM)php_rocs Wrote: @HarrysR, Yeap that's some very good questions i forgot to answer. So... I have two tables (for now) [products & manufacturers]. What i want to achieve is to upload a csv file and check if the manufacturer exists. If so, then i want to parse the id, and pass it to the "products" table. If not then create the manufacturer entry and get its ID. What i only get is that the column "manufacturer_id" (which is the one i want to get) can not be NULL.. And i don't know why i get this error. As far as i can see the query is right.... RE: Problem with inserting csv file entries to db - php_rocs - 05-17-2019 @HarrysR, What does your csv input look like (test data)? Also, what tools do you use to debug your code? Xdebug? echo statements? My guest is that there is a problem with your manufacturer-exist method. RE: Problem with inserting csv file entries to db - HarrysR - 05-19-2019 (05-17-2019, 05:53 AM)php_rocs Wrote: @HarrysR, Well i feel insanely stupid rn since the solution was really simple and silly. To begin with, to answer your question, i use "echo" statements. On the other hand as for the solution here's what was wrong. In my controller i had this: Code: $add_manuf = $this->product_model->add_manufacturer($manufacturer_data); While the model was like that: Code: public function add_manufacturer($data){ So (for people like me who didn't see that coming), while the function returned the last inserted_id of the query, i was trying to access the value as if the sql query returned a row_array. In two words.... i had to do it like this: Code: [BEFORE] Thank you for your interest in finding the problem guys! |