将图像插入bytea列显示0个字节

时间:2017-06-01 08:36:05

标签: php postgresql pdo blob bytea

数据库是:POSTGRESQL

数据库驱动程序:PDO

我的查询是:

INSERT INTO
poi (
    "idPoiCategory",
    name, 
    "shortName", 
    description, 
    url, 
    source, 
    "contactPostalCode", 
    "contactCity", 
    "contactAddress", 
    "contactPhone", 
    "contactPhone2", 
    "contactMail", 
    "mediaPhotoCopyright", 
    "mediaPhotoMain", 
    "mediaPhotoMiniature1", 
    "mediaPhotoMiniature2", 
    "mediaPhotoOriginalWidth", 
    "mediaPhotoOriginalHeight", 
    "mediaPhotoMiniatureWidth", 
    "mediaPhotoMiniatureHeight", 
    "mediaPhotoCropX", 
    "mediaPhotoCropY", 
    "mediaPhotoCropWidth", 
    "mediaPhotoCropHeight" 
)
VALUES (
    :id_poi_category, 
    :name, 
    :short_name, 
    :description, 
    :url, 
    :source, 
    :postal_code, 
    :city, 
    :street_with_number, 
    :phone_number_1, 
    :phone_number_2, 
    :mailto, 
    :photos_copyright, 
    :photo_main, 
    :photo_miniature_1, 
    :photo_miniature_2, 
    :photo_original_width, 
    :photo_original_height, 
    :photo_miniature_width, 
    :photo_miniature_height, 
    :photo_crop_x, 
    :photo_crop_y, 
    :photo_crop_width, 
    :photo_crop_height 
) 
RETURNING "idPoi" 

我使用以下方法绑定params(bytea):

$stmt->bindParam(':photo_main', $fields['photo_main'], PDO::PARAM_LOB);
$stmt->bindParam(':photo_miniature_1', $fields['photo_miniature_1'], PDO::PARAM_LOB);
$stmt->bindParam(':photo_miniature_2', $fields['photo_miniature_2'], PDO::PARAM_LOB);

问题是:为什么图像不会插入到bytea列中?其 (列)大小显示0个字节。我试图插入这些图像,但列仍显示0字节的大小。我试图将二进制数据转换为十六进制并将其转换为列 - 这是徒劳的,结果仍然是相同的:0字节。

1 个答案:

答案 0 :(得分:0)

问题在于Adminer。它报告列为“0字节”,即使你有数据。您可以使用SQL查询f.ex:octet_length(“column_name_with_bytea”)中的函数octet_length()来检查这一点。它应该报告大于0的值。