You could see this answers to rotate a PNG.
To save the image in DDBB, you could change the function of the link that i attached you with ob_get_content like this:
ob_start();
$im = imagecreatefrompng($DataImage);
// create a transparent "color" for the areas which will be new after rotation
// only quadratic images will not change dimensions
// r=0,b=0,g=0 ( black ), 127 = 100% transparency - we choose "invisible black"
$transparency = imagecolorallocatealpha( $im,0,0,0,127 );
// rotate, last parameter preserves alpha when true
$rotated = imagerotate( $im, 90, $transparency, 1);
// disable blendmode, we want real transparency
imagealphablending( $rotated, false );
// set the flag to save full alpha channel information
imagesavealpha( $rotated, true );
// we send image/png
imagepng( $rotated );
// save the result of imagepng in var "$imagedata" with ob_get_contents
$imagedata = ob_get_contents();
ob_end_clean();
imagedestroy( $im );
imagedestroy( $rotated );
Then, you will save $imagedata to your DDBB:
UPDATE your_table SET file_image = '.$imagedata.' WHERE .....