我正在尝试使用 PHP PDO 将值插入 PostgreSQL 数据库,但遇到以下错误消息:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: array value must start with "{" or dimension information
字段类型是PostgreSQL Array .
这是我的代码(简化版):
try {
$sql='INSERT INTO table (fieldName, foo) VALUES (?, ?)';
$fieldName=array('1','2');
$data=array($fieldName, 'bar'); # fieldName is array type in PostgreSQL
$STH = $conn->prepare($sql);
$STH->execute($data);
catch(PDOException $e) {
# Handle exception
}
谢谢!
最佳答案
以防万一有人遇到这种情况,解决方案是内爆数组并添加 {}。
$fieldName='{'.implode(",",$fieldName).'}';
关于php - PostgreSQL PDO 插入数组类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17244637/