![]() |
Transaction - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Transaction (/showthread.php?tid=76253) |
Transaction - pippuccio76 - 04-26-2020 HI sorry for english, in my controller i control if a record is a user's record before delete the record : PHP Code: function delete_device($id_record){ this is the fuction to control if record is is a user's record : PHP Code: function control_record_of_user($id_record,$user_id){ in my model i have a transaction in deleteDevice_plus_rimuovi_dispositivi: PHP Code: function deleteDevice_plus_rimuovi_dispositivi($record){ With transaction i have an error as the controller control many time if the record is a user's record : PHP Code: <h4>A PHP Error was encountered</h4> This is line number 658 if($device->id_user==$user_id){ The process work fine (but i see the error for half of second) if i delete only the record without transaction ( deleteDevice($record ) ) i haven't error . Why ? RE: Transaction - neuron - 04-26-2020 Error is not CI related, it is a general PHP error. Code: function control_record_of_user($id_record,$user_id){ In your method you are not checking if the get_Device method returning an object, if there is not record with that $id_record it might return NULL. Or as error says even if it returns something it is type maybe not an object but array. By running print_r($device) check what is inside of it. Also, I suggest to not run separate method to check if the record belongs to the user. Instead, build your SQL query with the condition for example: DELETE from records WHERE record_id = 2 and id_user = 56 Also, you can build DB constraints (Foreign key, DB relations). For example, you have users and users have records. In DB you can build a constraint saying if a user is deleted then delete its records also. This way you don't have to run separate queries, and use transactions. RE: Transaction - pippuccio76 - 04-26-2020 (04-26-2020, 09:52 AM)neuron Wrote: Error is not CI related, it is a general PHP error. The method : Code: public function get_Device($id_record){ return object because to delete must push on a button and with jquery i get the id to delete . With only deleteDevice($record) (in the model inside a transaction) called in place of deleteDevice_plus_rimuovi_dispositivi($record) not error are showing . For this : I suggest to not run separate method to check if the record belongs to the user. Instead, build your SQL query with the condition for example I do it to show the right mistake. |