1
我使用php在Postgres DB中存储了一点pdf(或txt,odt,doc)文件。 我用这个PHP函数读取文件:在php中使用postgres DB存储pdf远程文件
$fp = fopen($name, 'rb'); $content = fread($fp, filesize($name)); $content = addslashes($content); fclose($fp);
,然后尝试在数据库存储:
$sql = "insert into Table(column) values ('$content'::bytea)"; $result = @pg_query($sql);
“列” 是BYTEA类型。
当我用PDF文件执行脚本,我得到了如下错误:
ERROR: invalid byte sequence for encoding "UTF8": 0xe2e3cf HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".
当我和doc文件执行脚本,我得到了如下错误:
ERROR: invalid input syntax for type bytea
当我用txt文件执行脚本,否错误:
什么是错,什么是正确的方式来存储文件?
谢谢,pg_escape_bytea()而不是addslashes()正是我想要的。 – teosantoro 2011-03-11 14:43:51