· 9 years ago · Dec 26, 2016, 05:30 PM
1CREATE TABLE IF NOT EXISTS `images` (
2 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
3 `description` varchar(160) DEFAULT NULL,
4 `image` mediumblob,
5 PRIMARY KEY (`id`)
6) ENGINE=InnoDB DEFAULT CHARSET=utf8;
7
8$pdo = Database::getPDO($db);
9 $select_image_statement = $pdo->prepare(
10 "SELECT image FROM images WHERE id = :id"
11 );
12 $select_image_statement->bindParam(":id", $image_id);
13 $select_image_statement->execute();
14
15 $select_image_statement->bindColumn(1, $img, PDO::PARAM_LOB);
16
17 $select_image_statement->fetch(PDO::FETCH_BOUND);
18
19 $image = new Image();
20 $image->load($img);
21
22 $return = array(
23 'image' => $img,
24 'mime_type' => $image->getMimeType()
25 );
26
27 return $return;
28
29$dbh = new PDO("mysql:host={$db['host']};dbname={$db['name']}", $db['user'], $db['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));