| Linux in-mum-web1499.main-hosting.eu 5.14.0-503.40.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 5 06:06:04 EDT 2025 x86_64 Path : /home/u901718425/domains/cdn.urbanpillar.in/public_html/ |
| Current File : /home/u901718425/domains/cdn.urbanpillar.in/public_html/deleteNewsfeed.php |
<?php
include_once "conn.php";
$res = [];
$out = [];
// $pool = new ConnectionPool();
function query($query,$id, $pool = new ConnectionPool()){
$connection1 = $pool->getConnection();
if (!$connection1) {
die("Connection failed");
}
try{
// Prepare and execute the query
$stmt = $connection1->prepare($query);
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
// Execute the query
$result = $stmt->execute();
$out[0] = 'success';
$out[1] = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// Handle any connection or query errors
$out[0] = 'error';
$out[1] = $e;
} finally {
// Release the connection back to the pool
$pool->releaseConnection($connection1);
}
return $out;
}
if ($_POST) {
// id is only needed for update and identify the record, so we remove it from the array
$query = "SELECT * FROM `newsfeed` WHERE id = :id";
$result = query($query,$_POST['id']);
if($result[0] == 'success'){
if($result[1]){
foreach($result[1] as $key => $val){
if(file_exists($val['image'])){
unlink($val['image']);
}
}
}
}
$deleteQuery = "DELETE FROM `newsfeed` WHERE id = :id";
$deleteresult = query($deleteQuery,$_POST['id']);
work($_POST['updated_by'], $_POST['id'],'Delete Comment ');
$res[0] = 'success';
$res[1] = $deleteresult;
echo json_encode($res);
}
?>