Browse Source

added PDO::getBlob

Piotr Labudda 8 years ago
parent
commit
0b47e1e460
1 changed files with 25 additions and 0 deletions
  1. 25 0
      SE/se-lib/Core/Pdo.php

+ 25 - 0
SE/se-lib/Core/Pdo.php

@@ -628,4 +628,29 @@ EOF_STRUCT_MYSQL;
 		return $sth->rowCount();
 	}
 
+	public function getBlob($tableName, $fieldName, $pkField, $primaryKey) {
+		if (empty($tableName)) throw new Exception("Missing tableName in PDO::getBlob");
+		if (empty($fieldName)) throw new Exception("Missing fieldName in PDO::getBlob");
+		if (empty($pkField)) throw new Exception("Missing pkField in PDO::getBlob");
+		if (empty($primaryKey)) throw new Exception("Missing primaryKey in PDO::getBlob");
+		$dbType = $this->getType();
+		switch ($dbType) {
+			case 'mysql': {
+				$sql = "
+					select `{$fieldName}`
+					from `{$tableName}`
+					where `{$pkField}` = :pk
+					limit 1
+				";
+				$sth = $this->prepare($sql);
+				$sth->bindValue(':pk', $primaryKey, PDO::PARAM_STR);
+				$sth->execute();
+				$sth->bindColumn(1, $content, PDO::PARAM_LOB);
+				$sth->fetch();
+				return $content;
+			} break;
+			default: throw new Exception("Not implemented getBlob for database type '{$dbType}'");
+		}
+	}
+
 }