Delete prepared statement without effects on the database

Hi,

I’m trying to implement this flow:

  1. Receive file about a given date and shift;
  2. Delete any information about that date and shift that exists in the database;
  3. Insert the received information;

I’m having trouble with step two. The code I’m using is this:

 $cleanupSql = "DELETE FROM `Turnos` WHERE Dia = :Dia AND Turno  = :Turno ";
  
 $cleanupSth = $conn->prepare($cleanupSql);

 (...)
 $temp = date_format($date,"Y-m-d");
 $cleanupSth->bindParam(':Dia',$temp,PDO::PARAM_STR);
 $cleanupSth->bindParam(':Turno',$splited[2],PDO::PARAM_STR);
 $cleanupSth->execute();

$temp is equal to 2018-10-18 and splited[2] is “1”. dia of type date and Turno of type varchar.

I’ve also tried to use ? params, passing the dateTime object.

When I run this query in the database, which , it works

 DELETE FROM `Turnos` WHERE Dia = "2018-08-18" AND Turno  = "1"

@Supun @teodor @Infinity

@User2316
Can you try removing the PDO::PARAM_STR part from both bindParam functions? Lemme know the result.

I solved in the meantime. Had the problem with the string sanitization for the Turno parameter. But thank you for your attention.

1 Like

Glad to hear that you fixed it. Feel free to post here anytime.