jonsecu Posted March 5, 2014 Share Posted March 5, 2014 (edited) Hi... I am developing a module for prestashop and I have some issues with DB class. I want to retrieve the id of a table ($table) with email ($condition). I get that id with the getRowFromElement function, which returns an array. Since there is only one entry with any given email, the array has only one element. I retrieve this element with $results[0] which, for purposes of this post, assign to $delete var. Then I use $delete on Db::getInstance()->delete to erase from the db the entry with the id contained on $delete, and the code as it is below is not working. However, if I assign directly a number (say 114) to $delete, or replace $delete on Db::getInstance()->delete for the same number (114). It correctly deletes the entry from the db. I use that saveToLog function to see what is being returned by getRowFromElement, which is, as I expected, a 1 for the count of elements and the 114, the id of the entry with the required email. I need to pass the id returned from getRowFromElement to Db::getInstance()->delete... just I am stucked in here. I tried making a type cast (int) on $delete and still is not working. Any suggestion is welcome... thanks! I am running PS 1.5.3.1 on a local server with XAMPP. $inputName = $_POST['inputName']; $inputEmail = $_POST['inputEmail']; $inputMessage = $_POST['inputMessage']; $productID = $_POST['productID']; $table = 'pfm_dir'; $field = 'id_pfm_dir'; $where = 'email'; $condition = '[email protected]'; $results = getRowFromElement($field,$table,$where,$condition); saveToLog('people.log',count($results)." "); saveToLog('people.log',$results[0]); $delete = $results[0]; Db::getInstance()->delete($table, $field .' = '. $delete, 1, $use_cache = false); function saveDir($inputName, $inputEmail, $inputMessage) { Db::getInstance()->insert('pfm_dir', array( 'name' => pSQL($inputName), 'email' => pSQL($inputEmail), 'type' => pSQL($inputMessage), 'date_add' => date('Y-m-d H:i'), )); Edited March 5, 2014 by jonsecu (see edit history) Link to comment Share on other sites More sharing options...
Krystian Podemski Posted March 5, 2014 Share Posted March 5, 2014 I assume that your database prefix is pfm? If so that is a reason, there is a bug and delete doesnt work if you want to delete object from table named like: pfm_pfm_dir Link to comment Share on other sites More sharing options...
jonsecu Posted March 5, 2014 Author Share Posted March 5, 2014 I assume that your database prefix is pfm? If so that is a reason, there is a bug and delete doesnt work if you want to delete object from table named like: pfm_pfm_dir Hi Krystian... no the prefix is ps, the table name is ps_pfm_dir... I believe this is not related to the issue because when I hard code an integer as the index, either on $delete or directly on the delete query, the program deletes the correct entry on the table... however, if I try to pass it an integer resulting from evaluating getRowFromElement, the program deletes nothing. I can even pass a string such as $delete = '110'; and the program works. Link to comment Share on other sites More sharing options...
jonsecu Posted March 6, 2014 Author Share Posted March 6, 2014 Someone any idea? Link to comment Share on other sites More sharing options...
Maneesh Posted February 20, 2020 Share Posted February 20, 2020 Hi Jonsecu, Here is solution $id=Tools::getValue('startestdelete'); $deleteid = 'star_scroller_id ='. $id; Db::getInstance()->delete('star_scroller_text', $deleteid); For More Clear check link, http://doc.prestashop.com/pages/viewpage.action?pageId=51184692 Best Regards Maneesh Tiwari Link to comment Share on other sites More sharing options...
fredecs Posted December 12, 2020 Share Posted December 12, 2020 Instead of using ->delete method, use executeS method. Db::getInstance()->executeS('DELETE FROM '.$table.' WHERE '.$field.' = '.$value); Affected_Rows works normally! Link to comment Share on other sites More sharing options...
Guest Posted December 13, 2020 Share Posted December 13, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now