#26132 [Opn]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default #26132 [Opn]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP

    ID: 26132
    User updated by: steven at pearavenue dot com
    Reported By: steven at pearavenue dot com
    Status: Open
    Bug Type: PostgreSQL related
    Operating System: Redhat 9.0/Apache 2.0
    PHP Version: 4.3.4
    New Comment:

    You will want this SQL :

    $sql = "SELECT FeedID, uri

    FROM feeds ";


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-11-05 03:11:40] steven at pearavenue dot com

    Description:
    ------------
    I checked on PHP 5.0beta too and the same problem there.
    pg_fetch_object returns serial or integers as NULL while but returns
    varchars in the same record as string - pg_fetch_array returns the
    entire data correctly. Similar code worked fine on another server
    using MySQl Support.

    You need a table like this:
    CREATE TABLE public.feeds
    (
    feedid serial NOT NULL,
    uri varchar(255) NOT NULL DEFAULT '',
    category int4 NOT NULL DEFAULT 0,

    CONSTRAINT feeds_pkey PRIMARY KEY (feedid),
    CONSTRAINT feeds_uri_key UNIQUE (uri)
    ) WITH OIDS;



    Reproduce code:
    ---------------
    <?php
    $pgConnectStr = "... your connect string";
    $link = pg_connect( $pgConnectStr ) or die( "Could not connect" );

    $stat = pg_connection_status($link);
    if($stat == PGSQL_CONNECTION_OK ) {
    echo "connection_status: OK<br />";
    } else {
    // report connection error

    echo "connection_status: BAD<br />";
    echo( pg_last_error($link) );
    }

    $feedb = pg_query( $link, $sql);
    echo( "<br />".pg_num_rows( $feedb )." Number of rows returned.<br />"
    );
    // for each row in the table stuff the coresponding variables with the
    data:


    echo ( "ARRAY<br />" );

    while( $fields = pg_fetch_array( $feedb ) ){

    echo ( "<br />Feed[0]: $fields[0]<br />" );

    echo ( "<br />Feed[1]: {$fields[1]}<br />" );

    echo ( "<br />Feed[2]: {$fields[2]}<br />" );

    }



    echo ( "OBJECT<br />" );

    while( $row = pg_fetch_object( $feedb ) ){

    if( $row->FeedID == NULL) {
    $id = "NULL";
    } else {
    $id = $row->FeedID;
    }
    echo ( "<br />FeedID:".$id."<br />" );

    $uri = $row->uri;
    echo ( "<br />uri: $uri<br />" );

    if( $row->category == NULL) {
    $c = "NULL";
    } else {
    $c = $row->category;
    }
    echo ( "<br />category: $c<br />" );

    }
    ?>

    Expected result:
    ----------------
    We expect the serial and integer values to appear in the result from
    pg_fetch_object

    Actual result:
    --------------
    You will note that the output produces NULLs instead.


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=26132&edit=1[/url]
    steven at pearavenue dot com Guest

  2. Similar Questions and Discussions

    1. #26349 [Bgs]: is_numeric() returns false for strings with more than 308 characters
      ID: 26349 User updated by: kouber at saparev dot com Reported By: kouber at saparev dot com Status: Bogus Bug Type:...
    2. #26132 [Bgs]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP
      ID: 26132 User updated by: steven at pearavenue dot com Reported By: steven at pearavenue dot com Status: Bogus Bug...
    3. #26132 [Opn->Bgs]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP
      ID: 26132 Updated by: iliaa@php.net Reported By: steven at pearavenue dot com -Status: Open +Status: ...
    4. #26132 [NEW]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP
      From: steven at pearavenue dot com Operating system: Redhat 9.0/Apache 2.0 PHP version: 4.3.4 PHP Bug Type: PostgreSQL...
    5. Returns a NULL field ?
      Hi. I'm stuck! I am querying two tables in a DB using the following string SQLQuery = "SELECT GuestBook.*, GuestPic.PicName FROM GuestBook...
  3. #2

    Default #26132 [Opn]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP

    ID: 26132
    User updated by: steven at pearavenue dot com
    Reported By: steven at pearavenue dot com
    Status: Open
    Bug Type: PostgreSQL related
    Operating System: Redhat 9.0/Apache 2.0
    PHP Version: 4.3.4
    New Comment:

    Oh, and of course, you need to comment out either the ARRAY code or the
    OBJECT code when you test this. :) Try each in turn.


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-11-05 03:14:07] steven at pearavenue dot com

    You will want this SQL :

    $sql = "SELECT FeedID, uri

    FROM feeds ";

    ------------------------------------------------------------------------

    [2003-11-05 03:11:40] steven at pearavenue dot com

    Description:
    ------------
    I checked on PHP 5.0beta too and the same problem there.
    pg_fetch_object returns serial or integers as NULL while but returns
    varchars in the same record as string - pg_fetch_array returns the
    entire data correctly. Similar code worked fine on another server
    using MySQl Support.

    You need a table like this:
    CREATE TABLE public.feeds
    (
    feedid serial NOT NULL,
    uri varchar(255) NOT NULL DEFAULT '',
    category int4 NOT NULL DEFAULT 0,

    CONSTRAINT feeds_pkey PRIMARY KEY (feedid),
    CONSTRAINT feeds_uri_key UNIQUE (uri)
    ) WITH OIDS;



    Reproduce code:
    ---------------
    <?php
    $pgConnectStr = "... your connect string";
    $link = pg_connect( $pgConnectStr ) or die( "Could not connect" );

    $stat = pg_connection_status($link);
    if($stat == PGSQL_CONNECTION_OK ) {
    echo "connection_status: OK<br />";
    } else {
    // report connection error

    echo "connection_status: BAD<br />";
    echo( pg_last_error($link) );
    }

    $feedb = pg_query( $link, $sql);
    echo( "<br />".pg_num_rows( $feedb )." Number of rows returned.<br />"
    );
    // for each row in the table stuff the coresponding variables with the
    data:


    echo ( "ARRAY<br />" );

    while( $fields = pg_fetch_array( $feedb ) ){

    echo ( "<br />Feed[0]: $fields[0]<br />" );

    echo ( "<br />Feed[1]: {$fields[1]}<br />" );

    echo ( "<br />Feed[2]: {$fields[2]}<br />" );

    }



    echo ( "OBJECT<br />" );

    while( $row = pg_fetch_object( $feedb ) ){

    if( $row->FeedID == NULL) {
    $id = "NULL";
    } else {
    $id = $row->FeedID;
    }
    echo ( "<br />FeedID:".$id."<br />" );

    $uri = $row->uri;
    echo ( "<br />uri: $uri<br />" );

    if( $row->category == NULL) {
    $c = "NULL";
    } else {
    $c = $row->category;
    }
    echo ( "<br />category: $c<br />" );

    }
    ?>

    Expected result:
    ----------------
    We expect the serial and integer values to appear in the result from
    pg_fetch_object

    Actual result:
    --------------
    You will note that the output produces NULLs instead.


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=26132&edit=1[/url]
    steven at pearavenue dot com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139