V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
blankme
V2EX  ›  问与答

PHP 如何向 PostgreSQL 写入数组?

  •  
  •   blankme · Aug 7, 2017 · 1604 views
    This topic created in 3188 days ago, the information mentioned may be changed or developed.

    以下是 table 的定义:

    create table posts(
    	id text,
    	tag text[]
    );
    

    用 sql 语句可以插入数据:

    insert into posts (tag) values ('{a, b}');
    

    但用 php 会遇到问题:

    $insert_contents = array(
    	"id" => '1',
    	"tag" => '{a, b}',
    );
    $insert_result = pg_insert($dbconn, 'posts', $insert_contents);
    
    PHP Notice:  pg_insert(): Unknown or system data type '_text' for 'tag' in ...
    

    只找到一个解决方式是直接用 pg_query,请问在 php 中有没有更好的操作方式?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1054 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:32 · PVG 07:32 · LAX 16:32 · JFK 19:32
    ♥ Do have faith in what you're doing.