I need to delete a record from a table via PDO. I made some code (the same as below without the base64 encoding) and it worked. Then I added base64_encoding on my database and on the parameters send to MySQL. This is needed for various reasons, so I can't ditch the base64 encoding. Unfortunately this broke it (nothing happens in the database). I can't figure out how to debug this because the query doesn't throw an error. I followed this guide trying to debug it but nothing throws an error or is logged. Does anyone knows that the base64 format (for example:'siecX==') can cause issues in MySQL or PDO in general? My code:
<?php
$dbname="dbname";
$table="whitelisted_parameters";
session_start();
include_once(dirname(__DIR__)."../../config/database_conf.php");
try {
$conn = new PDO("mysql:host=$hostname; dbname=$dbname", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql= "DELETE FROM $table WHERE virtual_host_id=:id_virtual_host_selected AND `page`=:page AND `parameter`=:parameter AND `method`=:method";
$stmt = $conn->prepare($sql);
$stmt->bindParam(":id_virtual_host_selected", $_SESSION['id_virtual_host_selected'], PDO::PARAM_INT);
$fap=base64_encode($_POST['page']);
echo $fap."||";// I used a temp value to log the variables
$stmt->bindParam(":page", $fap, PDO::PARAM_STR);
$fap=base64_encode($_POST['parameter']);
echo $fap."||";
$stmt->bindParam(":parameter", $fap, PDO::PARAM_STR);
$fap=base64_encode($_POST['method']);
echo $fap."||";
$stmt->bindParam(":method", $fap, PDO::PARAM_STR);
$stmt->execute();
// Close DB connection
$dbh = null;
echo "parameter is removed";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>