pg_get_result() hangs for query length > 65535

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Ramsden

    pg_get_result() hangs for query length > 65535

    I have a script running on PHP v4.3.6 (cgi) that hangs forever
    in a call to the Postgres pg_get_result() function when and only
    when the query length is 65536 or more bytes.

    The query is a simple INSERT, of a single ASCII value into a
    'text' type field, and works fine for shorter queries.

    (As the code first calls pg_escape_strin g() on the value to be
    inserted, I'm sure the problem doesn't relate to bad characters
    in the data.)

    Anyone have any ideas? My impression is that few PHP coders use
    pg_send_query() and pg_get_result() , despite this being the only
    way (AFAIK) of getting specific error codes/text when something
    goes wrong (in which event pg_query() just returns false).

    The following is an extract from the offending code:

    if ($db_type == 'mysql')
    {
    $qry_id = @mysql_query ($x_qry, $x_db_conn);

    $g_db_err_no = mysql_errno ();
    $g_db_err_str = mysql_error ();
    }

    else if ($db_type == 'postgres')
    {
    # Because pg_query() returns FALSE if the query fails, one must must
    # use pg_send_query() and pg_get_result() to get the result handle.
    #
    # $qry_id = @pg_query ($x_db_conn, $x_qry);
    #
    if (! pg_send_query ($x_db_conn, $x_qry))
    {
    die ("pg_send_query ");
    }


    !!!!!!!! QUERY OF LENGTH 64K OR MORE HANGS IN FOLLOWING pg_get_result() CALL


    if (! ($qry_id = pg_get_result ($x_db_conn)))
    {
    die ("pg_get_result ");
    }

    # jr.debug
    error_log (" past pg_get_result() !\n", 3, '/tmp/hack.log');

    # pg_result_error (), available from PHP v4.2.0+, like pg_result_statu s(),
    # returns a better result then pg_last_error() , as the latter may be set
    # by all kinds of internal calls and thus not reflect the app-level error.
    #
    $g_db_err_no = pg_result_statu s ($qry_id);
    $g_db_err_str = pg_result_error ($qry_id);
    }

    else if ($db_type == 'mssql')
    {

    :::



    Cheers

    John R Ramsden (john_ramsden@s agitta-ps.cam) <-- com not cam
  • steve

    #2
    Re: pg_get_result() hangs for query length &gt; 65535

    "John Ramsden" wrote:[color=blue]
    > I have a script running on PHP v4.3.6 (cgi) that hangs forever
    > in a call to the Postgres pg_get_result() function when and only
    > when the query length is 65536 or more bytes.
    >
    > The query is a simple INSERT, of a single ASCII value into a
    > ’text’ type field, and works fine for shorter queries.
    >
    > (As the code first calls pg_escape_strin g() on the value to be
    > inserted, I’m sure the problem doesn’t relate to bad
    > characters
    > in the data.)
    >
    > Anyone have any ideas? My impression is that few PHP coders use
    > pg_send_query() and pg_get_result() , despite this being the only
    > way (AFAIK) of getting specific error codes/text when something
    > goes wrong (in which event pg_query() just returns false).
    >
    > The following is an extract from the offending code:
    >
    > if ($db_type == ’mysql’)
    > {
    > $qry_id = @mysql_query ($x_qry, $x_db_conn);
    >
    > $g_db_err_no = mysql_errno ();
    > $g_db_err_str = mysql_error ();
    > }
    >
    > else if ($db_type == ’postgres’)
    > {
    > # Because pg_query() returns FALSE if the query fails, one[/color]
    must[color=blue]
    > must
    > # use pg_send_query() and pg_get_result() to get the result
    > handle.
    > #
    > # $qry_id = @pg_query ($x_db_conn, $x_qry);
    > #
    > if (! pg_send_query ($x_db_conn, $x_qry))
    > {
    > die ("pg_send_query ");
    > }
    >
    >
    > !!!!!!!! QUERY OF LENGTH 64K OR MORE HANGS IN FOLLOWING
    > pg_get_result() CALL
    >
    >
    > if (! ($qry_id = pg_get_result ($x_db_conn)))
    > {
    > die ("pg_get_result ");
    > }
    >
    > # jr.debug
    > error_log (" past pg_get_result() !\n", 3,
    > ’/tmp/hack.log’);
    >
    > # pg_result_error (), available from PHP v4.2.0+, like
    > pg_result_statu s(),
    > # returns a better result then pg_last_error() , as the latter[/color]
    may[color=blue]
    > be set
    > # by all kinds of internal calls and thus not reflect the
    > app-level error.
    > #
    > $g_db_err_no = pg_result_statu s ($qry_id);
    > $g_db_err_str = pg_result_error ($qry_id);
    > }
    >
    > else if ($db_type == ’mssql’)
    > {
    >
    > :::
    >
    >
    >
    > Cheers
    >
    > John R Ramsden (john_ramsden@s agitta-ps.cam) <-- com not cam[/color]

    Have you posted to a postgres newsgroup (if there is one, worth
    checking)? Since you have not had a reply I venture a guess, based on
    mysql. In mysql, you have a packet size variable that needs to be set
    to a large value if the query result are big. There may be a similar
    setting in postgres. My guess is that this relates to postgres and
    not php.

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-pg_get_r...ict138691.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=467219

    Comment

    Working...