Reading boolean correctly from Postgres by PHP

后端 未结 4 1144
野性不改
野性不改 2021-02-14 14:58

The main problem of this thread is moved to here about boolean datatype in PHP / Postgres.

The problem is the conversion of t and f to

4条回答
  •  遥遥无期
    2021-02-14 15:43

    I wrote a function in postgres to export boolean to PHP readable boolean:

    You just use it this way:

    SELECT php_bool(columna) from
    table
    

    Here is the function:

    CREATE OR REPLACE FUNCTION php_bool(boolean)
    RETURNS numeric LANGUAGE plpgsql
    
    AS
    $BODY$
    
    BEGIN
    
      IF $1 = true THEN
        RETURN 1;
      ELSE
        RETURN 0;
      END IF;
    END
    $BODY$
    

提交回复
热议问题