Ms7 Search
Google 搜尋 翻譯
calendar
« 九月 2024 »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
近期文章
文章分類
網站連結
Syndicate

« | »

PostgreSql bytea 字段存檔讀取 php

2013-06-01 @ 13:20 in PHP, JavaScript, Sql

在 php  存入時
$data = pg_escape_bytea($fileContents) //轉義bytea數據類型的二進制字符串

在 讀取時用
$fileContents = pg_unescape_bytea($data) //獲得二進制數據

導出文件後,如果二進制數據轉碼錯誤就會出現文件打不開的現象,這是因為 postgresql.conf 內定將 bytea_output = 'hex'
有兩種方法可以解決
將 postgresql.conf 內的 bytea_output='hex' 改成 bytea_output='escape' ,說得將前面的#取消,重新讀取 postgresql.conf 
或則
執行 ALTER DATABASE database_name SET bytea_output TO 'escape' ;     //只設定所用資料庫的 bytea_output 的輸出

發表迴響
 authimage