No connection with database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joachim Smit

    #1

    No connection with database


    I want store data in 2 different database, just for backup. One database
    is located at the webserver, the 2nd one on another server.

    I've writte this little script to test it.

    <?php
    $db1 = pg_connect("hos t=123.123.123.1 23 dbname=test user=usrphp");
    $cmd = "insert into website (ipnr, page) values ('777', 'main')";
    $result = pg_query($db1, $cmd);

    $db2 = pg_connect("dbn ame=test user=usrphp");
    $cmd = "insert into website (ipnr, page) values ('777', 'main')";
    $result = pg_query($db2, $cmd);

    echo ($db1);
    echo ("\n");

    echo ($db2);
    echo ("\n");

    pg_close($db1);
    pg_close($db2);

    ?>

    When I call this script from the command prompt, I get the result:

    Resource id #1
    Resource id #3

    and the data is written to both databases.

    When I call the script with a browser from outside, I get the result:

    Resource id #2

    Data is written only to the local database.

    Why ?


    Many thanks in advance.

    Joachim
  • Jerry Stuckle

    #2
    Re: No connection with database

    Joachim Smit wrote:
    >
    I want store data in 2 different database, just for backup. One database
    is located at the webserver, the 2nd one on another server.
    >
    I've writte this little script to test it.
    >
    <?php
    $db1 = pg_connect("hos t=123.123.123.1 23 dbname=test user=usrphp");
    $cmd = "insert into website (ipnr, page) values ('777', 'main')";
    $result = pg_query($db1, $cmd);
    >
    $db2 = pg_connect("dbn ame=test user=usrphp");
    $cmd = "insert into website (ipnr, page) values ('777', 'main')";
    $result = pg_query($db2, $cmd);
    >
    echo ($db1);
    echo ("\n");
    >
    echo ($db2);
    echo ("\n");
    >
    pg_close($db1);
    pg_close($db2);
    >
    ?>
    >
    When I call this script from the command prompt, I get the result:
    >
    Resource id #1
    Resource id #3
    >
    and the data is written to both databases.
    >
    When I call the script with a browser from outside, I get the result:
    >
    Resource id #2
    >
    Data is written only to the local database.
    >
    Why ?
    >
    >
    Many thanks in advance.
    >
    Joachim
    Which is just what should happen.

    When you run it from the command line on your machine, $db2 will be a
    connection to your machine, because that's where the PHP is running.

    When you execute it from a browser, the script is being executed by the
    server, and $db2 would point to a database one the server - which would
    be something entirely different.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Joachim Smit

      #3
      Re: No connection with database

      >
      Which is just what should happen.
      >
      When you run it from the command line on your machine, $db2 will be a
      connection to your machine, because that's where the PHP is running.
      >
      When you execute it from a browser, the script is being executed by the
      server, and $db2 would point to a database one the server - which would
      be something entirely different.
      >
      There is no difference between my machine and the server. I run the
      script from the command prompt on the server. In both cases the same
      script runs on the same server. The only difference is the way I call
      the script.

      Joachim

      Comment

      • Jerry Stuckle

        #4
        Re: No connection with database

        Joachim Smit wrote:
        >>
        >Which is just what should happen.
        >>
        >When you run it from the command line on your machine, $db2 will be a
        >connection to your machine, because that's where the PHP is running.
        >>
        >When you execute it from a browser, the script is being executed by
        >the server, and $db2 would point to a database one the server - which
        >would be something entirely different.
        >>
        >
        There is no difference between my machine and the server. I run the
        script from the command prompt on the server. In both cases the same
        script runs on the same server. The only difference is the way I call
        the script.
        >
        Joachim
        Ok, then how about the user privileges? When you call it from the
        browser you're running under a different ID than when you're calling
        from the command line.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Joachim Smit

          #5
          Re: No connection with database

          Ok, then how about the user privileges? When you call it from the
          browser you're running under a different ID than when you're calling
          from the command line.
          >
          Does it make any difference?

          iptables and pg_hba.conf are allright on the external server. I don't
          need to make any changes there, I think.

          What could I change on the internal server?

          Joachim

          Comment

          • Jerry Stuckle

            #6
            Re: No connection with database

            Joachim Smit wrote:
            >Ok, then how about the user privileges? When you call it from the
            >browser you're running under a different ID than when you're calling
            >from the command line.
            >>
            >
            Does it make any difference?
            >
            iptables and pg_hba.conf are allright on the external server. I don't
            need to make any changes there, I think.
            >
            What could I change on the internal server?
            >
            Joachim
            It sure can. This has nothing to do with iptables, pg_hba.conf or
            anything similar.

            There are many things which could be different. The userid is the
            first; it could also be you're using a different version of PHP when
            running through a web server vs. the command line, could be loading a
            different pg library - a lot of things.

            You need to find out what's different between the two. Because if the
            environment were the same, the script would work the same.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            Working...