我无法将 postgresql 数组转换为 php 数组。 这是我的数组 列是字符 varying[],这里是值 {image1,image2,image3}
$imgArry 始终为空。
$query = "SELECT \"A\".\"id\",
array_to_json(\"A\".images)
FROM
public.A " ;
$rs = pg_query($db, $query) or
die("Cannot execute query: $query\n");
$index = 0;
while ($row = pg_fetch_assoc($rs)) {
$A->id = $row["id"];
$imgArry = json_decode($row["images"]);
$planproduct->image=$imgArry[0];
最佳答案
这样做。
preg_match('/^{(.*)}$/', $row["images"], $matches);
$imgArry=str_getcsv($matches[1]);
关于php - 查询 postgresql 数组列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17283026/