<?php
try {
//include('x.php');//x.php has the connection string below.
$handler = new PDO('mysql:host=127.0.0.1;dbname=thedatabase;', 'theusername', 'thepassword'); //Setting the handler. See next line if this line fails.
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //Setting the attributes for the handler that we want to see if exception error.
}
//global $handler
catch(PDOException $e) { //Return the PDO exception and naming it $e.
// echo 'Caught';
// die('Sorry database problem.'); //Production message.
echo $e->getMessage(); //Show specific error message. Development.
}
// $id = htmlentities($argv[1]);
$id = htmlentities($_GET['id']);
// $id = "55";
$query = $handler->prepare("select * from blobimages where id = :id;");
$query->bindParam(':id',$id);
$query->execute();
while($r=$query->fetch(PDO::FETCH_OBJ)){
$imageData = $r->image;
$imageType = $r->filetype;
$imageName = $r->name;
//Header that gets sent to the browser.
header("content-type: $imageType");
//Display the image:
echo $imageData;
}
?>
SQLSTATE[HY000] [1045] Access denied for user 'theusername'@'localhost' (using password: YES)