Error management : php-pgsql.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David W

    Error management : php-pgsql.

    Hello,

    My goal : obtain the error message if the connection fail.

    ## my code :

    <?php

    $cnxString = "host=local host port=5432 dbname=toto user=atlante
    password=aiThoo 3g";

    $pgsql_conn = pg_connect($cnx String, PGSQL_CONNECT_F ORCE_NEW);

    if ($pgsql_conn) {
    print "Connexion réussie à : " . pg_host($pgsql_ conn) . "<br/>\n";
    } else {
    echo pg_last_notice( $pgsql_conn);
    exit;
    }
    ?>

    ## if «php_value display_errors 1» the screen result is this one :

    Warning: pg_connect() [function.pg-connect]: Unable to connect to
    PostgreSQL server: FATAL: la base de données «toto» n'existe pas in
    /home/willou/public_html/atlanpolis/wwws/tools/checkdb.php on line 5

    Warning: pg_last_notice( ) expects parameter 1 to be resource, boolean
    given in /home/willou/public_html/atlanpolis/wwws/tools/checkdb.php on
    line 10

    ## If not, i haven't got any result. The message just appears in my
    logs

    The return of pg_connect not seems to be an connection resource when
    the connection fails.

    Thanks to help me to find the problem,
    David.

  • Colin Fine

    #2
    Re: Error management : php-pgsql.

    David W wrote:[color=blue]
    > Hello,
    >
    > My goal : obtain the error message if the connection fail.
    >
    > ## my code :
    >
    > <?php
    >
    > $cnxString = "host=local host port=5432 dbname=toto user=atlante
    > password=aiThoo 3g";
    >
    > $pgsql_conn = pg_connect($cnx String, PGSQL_CONNECT_F ORCE_NEW);
    >
    > if ($pgsql_conn) {
    > print "Connexion réussie à : " . pg_host($pgsql_ conn) . "<br/>\n";
    > } else {
    > echo pg_last_notice( $pgsql_conn);
    > exit;
    > }
    > ?>
    >
    > ## if «php_value display_errors 1» the screen result is this one :
    >
    > Warning: pg_connect() [function.pg-connect]: Unable to connect to
    > PostgreSQL server: FATAL: la base de données «toto» n'existe pas in
    > /home/willou/public_html/atlanpolis/wwws/tools/checkdb.php on line 5
    >
    > Warning: pg_last_notice( ) expects parameter 1 to be resource, boolean
    > given in /home/willou/public_html/atlanpolis/wwws/tools/checkdb.php on
    > line 10
    >
    > ## If not, i haven't got any result. The message just appears in my
    > logs
    >
    > The return of pg_connect not seems to be an connection resource when
    > the connection fails.
    >
    > Thanks to help me to find the problem,
    > David.
    >[/color]

    I see you have posted the same question on:
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    On that page, it says:
    =============== =============== =============== =============== ======
    Return Values

    PostgreSQL connection resource on success, FALSE on failure.
    =============== =============== =============== =============== ======

    I admit that it does not give an example about error handling.


    On http://uk.php.net/manual/en/function.pg-last-error.php, it says

    =============== =============== =============== =============== ============
    Parameters

    connection

    PostgreSQL database connection resource. When connection is not
    present, the default connection is used. The default connection is the
    last connection made by pg_connect() or pg_pconnect().
    =============== =============== =============== =============== ============

    which suggests that you can say

    if ($pgsql_conn) {
    print "Connexion réussie à : " . pg_host($pgsql_ conn) . "<br/>\n";
    } else {
    echo pg_last_notice( );
    exit;
    }

    but I have not tried it. The example on that page does what you have
    done, which suggests that you have found a bug either in the code or in
    the documentation.


    Sorry I can't be more helpful

    Colin

    Comment

    • David W

      #3
      Re: Error management : php-pgsql.

      Hello,

      thanks for your support but i'v soon tried to call pg_last_notice( )
      without parameters. But the problem stay the same, it tell me that
      there's not postgresql connection.

      Bye,
      David.

      Comment

      • Gordon Burditt

        #4
        Re: Error management : php-pgsql.

        >## if «php_value display_errors 1» the screen result is this one :[color=blue]
        >
        >Warning: pg_connect() [function.pg-connect]: Unable to connect to
        >PostgreSQL server: FATAL: la base de données «toto» n'existe pas in
        >/home/willou/public_html/atlanpolis/wwws/tools/checkdb.php on line 5[/color]

        The error messages says that database 'toto' does not exist (assuming
        I have interpreted it correctly). *DOES* it exist? Is that wierd
        crap surrounding 'toto' some odd extra character that got into the
        database name, or something else? Can you connect to that database
        using a PostgreSQL command-line tool using the same connect info?

        Gordon L. Burditt

        Comment

        • Colin Fine

          #5
          Re: Error management : php-pgsql.

          Gordon Burditt wrote:[color=blue][color=green]
          >>## if «php_value display_errors 1» the screen result is this one :
          >>
          >>Warning: pg_connect() [function.pg-connect]: Unable to connect to
          >>PostgreSQL server: FATAL: la base de données «toto» n'existe pas in
          >>/home/willou/public_html/atlanpolis/wwws/tools/checkdb.php on line 5[/color]
          >
          >
          > The error messages says that database 'toto' does not exist (assuming
          > I have interpreted it correctly). *DOES* it exist? Is that wierd
          > crap surrounding 'toto' some odd extra character that got into the
          > database name, or something else? Can you connect to that database
          > using a PostgreSQL command-line tool using the same connect info?
          >
          > Gordon L. Burditt[/color]
          That 'wierd crap' is French for quotes. Don't worry about it.

          But I think the OP is concerned about the error handling, not the
          original error - and rightly: it looks like a bug to me (though I
          suppose it might be that something doesn't support French properly).

          Colin

          Comment

          Working...