Home > Software engineering >  how to delete the picture from directory after query (mysql php)?
how to delete the picture from directory after query (mysql php)?

Time:01-15

how to delete the picture inside dir based on condition, like should i make another query before deleting from mysql or there is a way to do both at the same time

   $user_id= $_POST['user_id'];
   $ServerURL = 'http://10.0.2.2/users/pics/';

           $stmt = $PDO->prepare("
              
               
                DELETE FROM  user_picture 
                WHERE user_picture.album_id = (
                SELECT user_album.album_id 
                FROM user_album WHERE
                user_album.user_id= :USERID);

                DELETE FROM user_album 
                WHERE user_album.user_id= :USERID;");

      $stmt->bindParam(':USERID', $user_id);

    if($stmt->execute()){
        $returnApp = array( 'DELETE' =>'LOAD_SUCCESS');         
        echo json_encode($returnApp);
        
    }else{
        
        $returnApp = array( 'DELETE' => 'LOAD_FAILD');
     

}

CodePudding user response:

Some database engines, like Postgres, allow You to use RETURNING clause, like this:

DELETE FROM <table>
WHERE <conditions>
RETURNING id

The query deletes rows based on conditions and returns table of deleted rows, as if You queried them like this before deleting:

SELECT id
FROM <table>
WHERE <condition>

As far as I know, this is not part of SQL standard and is engine-specific. For Postgres, see https://www.postgresql.org/docs/14/dml-returning.html

  •  Tags:  
  • Related