Jump to content

Issues with Db::getInstance()->delete


jonsecu

Recommended Posts

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 by jonsecu (see edit history)
Link to comment
Share on other sites

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

  • 5 years later...
  • 9 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...