PostgreSql bytea 字段存檔讀取 php
在 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 的輸出