php - 查询 postgresql 数组列

标签 php postgresql

我无法将 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/

相关文章:

postgresql - 我什么时候需要将值转换为日期?

ruby-on-rails - 如何防止数据库连接在 Rails 中超时?

ruby-on-rails - 计算数组中的项目跨越数千条记录的 100 条

php - 如何将我的 angularjs 变量传递给 Php 页面并检索它

javascript - WordPress 网站 : homepage redirects to "login" page (non-existent now)

PHP 为什么会无限循环?

ruby-on-rails - 如何查询所有没有特定关联的记录而不将它们全部加载到内存中?

php - Symfony2 : Auth using Doctrine2 entity - password set to blank value after saving an entity

php - 创建订购和结帐系统,防止在付款期间更改购物车

postgresql - 为什么在使用覆盖索引时 Postgres 仍然进行位图堆扫描?