Thread: PHP-Postgres link

PHP-Postgres link

From
"Ramses v. Pinxteren"
Date:
Hi,

I am running PHP under APache with a link to a postgres database. It gives
me a headache because it is not working.

I am running Apache as nobody, and I have made a Postgres user also named
nobody.

I made a postgres database users (as nobody: createdb users) and with psql a
database login (field 1: userindex, field 2 username, field 3 password,
field 4 security level)

with psql i can do everything I want with this table. adding tuples,
deleting them etc. etc.

Now what do i need: I need a script that adds a new user to this database.
so I created this:
<?
        $connection = pg_connect("", "", "", "users");
        echo ("$connection");
        $query = "INSERT INTO users.login VALUES ( '$userindex', '$uname',
'$passwrd1', '1')";
        echo ("$query");
        $result = pg_exec ($connection, "select *");
        print (pg_cmdtuples($result));
        pg_close($connection);
?>

This generates an error at the HTML output:

1INSERT INTO login VALUES ( '1', 'test', 'test', '1');
Warning: PostgresSQL query failed: ERROR: login: Table does not exist. in
/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 6

Warning: 0 is not a PostgresSQL result index in
/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 7


in the logffiles is specifies:
FindExec: found "/usr/local/postgres/bin/postgres" using argv[0]
started: host=localhost user=nobody database=users
InitPostgres
StartTransactionCommand
ERROR:  login: Table does not exist.
AbortCurrentTransaction
proc_exit(0) [#0]
shmem_exit(0) [#0]
exit(0)
/usr/local/postgres/bin/postmaster: reaping dead processes...
/usr/local/postgres/bin/postmaster: CleanupProc: pid 19113 exited with
status 0


I am a complete newby, so please go easy on me!

Tnx!
Ramses





Re: PHP-Postgres link

From
Tatsuo Ishii
Date:
> I am running PHP under APache with a link to a postgres database. It gives
> me a headache because it is not working.
>
> I am running Apache as nobody, and I have made a Postgres user also named
> nobody.
>
> I made a postgres database users (as nobody: createdb users) and with psql a
> database login (field 1: userindex, field 2 username, field 3 password,
> field 4 security level)
>
> with psql i can do everything I want with this table. adding tuples,
> deleting them etc. etc.
>
> Now what do i need: I need a script that adds a new user to this database.
> so I created this:
> <?
>         $connection = pg_connect("", "", "", "users");
>         echo ("$connection");
>         $query = "INSERT INTO users.login VALUES ( '$userindex', '$uname',
                ~~~~~~~~~~~Are you sure with this?
PostgreSQL does not accept "database.table" notion.

> '$passwrd1', '1')";
>         echo ("$query");
>         $result = pg_exec ($connection, "select *");
>         print (pg_cmdtuples($result));
>         pg_close($connection);
> ?>
>
> This generates an error at the HTML output:
>
> 1INSERT INTO login VALUES ( '1', 'test', 'test', '1');
> Warning: PostgresSQL query failed: ERROR: login: Table does not exist. in
> /usr/local/apache/htdocs/isis.cx/database_update.php3 on line 6
>
> Warning: 0 is not a PostgresSQL result index in
> /usr/local/apache/htdocs/isis.cx/database_update.php3 on line 7
>
>
> in the logffiles is specifies:
> FindExec: found "/usr/local/postgres/bin/postgres" using argv[0]
> started: host=localhost user=nobody database=users
> InitPostgres
> StartTransactionCommand
> ERROR:  login: Table does not exist.
> AbortCurrentTransaction
> proc_exit(0) [#0]
> shmem_exit(0) [#0]
> exit(0)
> /usr/local/postgres/bin/postmaster: reaping dead processes...
> /usr/local/postgres/bin/postmaster: CleanupProc: pid 19113 exited with
> status 0

Another possibility is you have two postmasters running. You connect
to wrong postmaster?
--
Tatsuo Ishii


Re: PHP-Postgres link

From
Charles Tassell
Date:
Try replacing $connection = pg_connect("", "", "", "users"); with
$connection = pg_connect("dbname=users")   or you might want to try
$connection = pg_connect("dbname=users user=nobody")

At 11:53 AM 4/9/00, Ramses v. Pinxteren wrote:
>Hi,
>
>I am running PHP under APache with a link to a postgres database. It gives
>me a headache because it is not working.
>
>I am running Apache as nobody, and I have made a Postgres user also named
>nobody.
>
>I made a postgres database users (as nobody: createdb users) and with psql a
>database login (field 1: userindex, field 2 username, field 3 password,
>field 4 security level)
>
>with psql i can do everything I want with this table. adding tuples,
>deleting them etc. etc.
>
>Now what do i need: I need a script that adds a new user to this database.
>so I created this:
><?
>         $connection = pg_connect("", "", "", "users");
>         echo ("$connection");
>         $query = "INSERT INTO users.login VALUES ( '$userindex', '$uname',
>'$passwrd1', '1')";
>         echo ("$query");
>         $result = pg_exec ($connection, "select *");
>         print (pg_cmdtuples($result));
>         pg_close($connection);
>?>
>
>This generates an error at the HTML output:
>
>1INSERT INTO login VALUES ( '1', 'test', 'test', '1');
>Warning: PostgresSQL query failed: ERROR: login: Table does not exist. in
>/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 6
>
>Warning: 0 is not a PostgresSQL result index in
>/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 7
>
>
>in the logffiles is specifies:
>FindExec: found "/usr/local/postgres/bin/postgres" using argv[0]
>started: host=localhost user=nobody database=users
>InitPostgres
>StartTransactionCommand
>ERROR:  login: Table does not exist.
>AbortCurrentTransaction
>proc_exit(0) [#0]
>shmem_exit(0) [#0]
>exit(0)
>/usr/local/postgres/bin/postmaster: reaping dead processes...
>/usr/local/postgres/bin/postmaster: CleanupProc: pid 19113 exited with
>status 0
>
>
>I am a complete newby, so please go easy on me!
>
>Tnx!
>Ramses
>
>
>


Re: PHP-Postgres link

From
Keith
Date:
The users.login part is unnessary.  Just put the table name there.  In PHP you
connect to the database, then work on the tables.

"Ramses v. Pinxteren" wrote:

> Hi,
>
> I am running PHP under APache with a link to a postgres database. It gives
> me a headache because it is not working.
>
> I am running Apache as nobody, and I have made a Postgres user also named
> nobody.
>
> I made a postgres database users (as nobody: createdb users) and with psql a
> database login (field 1: userindex, field 2 username, field 3 password,
> field 4 security level)
>
> with psql i can do everything I want with this table. adding tuples,
> deleting them etc. etc.
>
> Now what do i need: I need a script that adds a new user to this database.
> so I created this:
> <?
>         $connection = pg_connect("", "", "", "users");
>         echo ("$connection");
>         $query = "INSERT INTO users.login VALUES ( '$userindex', '$uname',
> '$passwrd1', '1')";
>         echo ("$query");
>         $result = pg_exec ($connection, "select *");
>         print (pg_cmdtuples($result));
>         pg_close($connection);
> ?>
>
> This generates an error at the HTML output:
>
> 1INSERT INTO login VALUES ( '1', 'test', 'test', '1');
> Warning: PostgresSQL query failed: ERROR: login: Table does not exist. in
> /usr/local/apache/htdocs/isis.cx/database_update.php3 on line 6
>
> Warning: 0 is not a PostgresSQL result index in
> /usr/local/apache/htdocs/isis.cx/database_update.php3 on line 7
>
> in the logffiles is specifies:
> FindExec: found "/usr/local/postgres/bin/postgres" using argv[0]
> started: host=localhost user=nobody database=users
> InitPostgres
> StartTransactionCommand
> ERROR:  login: Table does not exist.
> AbortCurrentTransaction
> proc_exit(0) [#0]
> shmem_exit(0) [#0]
> exit(0)
> /usr/local/postgres/bin/postmaster: reaping dead processes...
> /usr/local/postgres/bin/postmaster: CleanupProc: pid 19113 exited with
> status 0
>
> I am a complete newby, so please go easy on me!
>
> Tnx!
> Ramses


Re: PHP-Postgres link

From
"omid omoomi"
Date:
Hi,
Do you still have your problem? Have you try this :
$query = "INSERT INTO login('$userindex' , '$uname','$passwrd1', '1')";

Also "LOGIN" might be a reserved word, it would be better if you put another
name for your table.


Regards
Omid Omoomi

>From: "Ramses v. Pinxteren" <ram6@euronet.nl>
>To: pgsql-general@postgresql.org
>Subject: [GENERAL] PHP-Postgres link
>Date: Sun, 9 Apr 2000 16:53:25 +0200
>
>Hi,
>
>I am running PHP under APache with a link to a postgres database. It gives
>me a headache because it is not working.
>
>I am running Apache as nobody, and I have made a Postgres user also named
>nobody.
>
>I made a postgres database users (as nobody: createdb users) and with psql
>a
>database login (field 1: userindex, field 2 username, field 3 password,
>field 4 security level)
>
>with psql i can do everything I want with this table. adding tuples,
>deleting them etc. etc.
>
>Now what do i need: I need a script that adds a new user to this database.
>so I created this:
><?
>         $connection = pg_connect("", "", "", "users");
>         echo ("$connection");
>         $query = "INSERT INTO users.login VALUES ( '$userindex', '$uname',
>'$passwrd1', '1')";
>         echo ("$query");
>         $result = pg_exec ($connection, "select *");
>         print (pg_cmdtuples($result));
>         pg_close($connection);
>?>
>
>This generates an error at the HTML output:
>
>1INSERT INTO login VALUES ( '1', 'test', 'test', '1');
>Warning: PostgresSQL query failed: ERROR: login: Table does not exist. in
>/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 6
>
>Warning: 0 is not a PostgresSQL result index in
>/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 7
>
>
>in the logffiles is specifies:
>FindExec: found "/usr/local/postgres/bin/postgres" using argv[0]
>started: host=localhost user=nobody database=users
>InitPostgres
>StartTransactionCommand
>ERROR:  login: Table does not exist.
>AbortCurrentTransaction
>proc_exit(0) [#0]
>shmem_exit(0) [#0]
>exit(0)
>/usr/local/postgres/bin/postmaster: reaping dead processes...
>/usr/local/postgres/bin/postmaster: CleanupProc: pid 19113 exited with
>status 0
>
>
>I am a complete newby, so please go easy on me!
>
>Tnx!
>Ramses
>
>
>
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


Re: PHP-Postgres link

From
Serj MD
Date:
Hello,
I don't speak english, I'm sorry
My example:

$connection = pg_connect("", "", "", "users");
$query = pg_exec($connection, "INSERT INTO login VALUES ( '$userindex', '$uname', '$password', '1')");
$result = pg_exec ($connection, "select * from login");
$num = pgNumRows($result);
for($i = 0; $i < $num; $i++)
{
echo pg_result($result, $i, "userindex") . " | " . pg_result($result, $i, "username") . " | " .  pg_result($result, $i,
"password"). " | " .pg_result($result, $i, "field  4???") . " <BR> " .   
}


???????????????????????????????

Best regards,
Serj MD

> Hi,
> Do you still have your problem? Have you try this :
> $query = "INSERT INTO login('$userindex' , '$uname','$passwrd1', '1')";
>
> Also "LOGIN" might be a reserved word, it would be better if you put another
> name for your table.
>
>
> Regards
> Omid Omoomi
>
> >From: "Ramses v. Pinxteren" <ram6@euronet.nl>
> >To: pgsql-general@postgresql.org
> >Subject: [GENERAL] PHP-Postgres link
> >Date: Sun, 9 Apr 2000 16:53:25 +0200
> >
> >Hi,
> >
> >I am running PHP under APache with a link to a postgres database. It gives
> >me a headache because it is not working.
> >
> >I am running Apache as nobody, and I have made a Postgres user also named
> >nobody.
> >
> >I made a postgres database users (as nobody: createdb users) and with psql
> >a
> >database login (field 1: userindex, field 2 username, field 3 password,
> >field 4 security level)
> >
> >with psql i can do everything I want with this table. adding tuples,
> >deleting them etc. etc.
> >
> >Now what do i need: I need a script that adds a new user to this database.
> >so I created this:
> ><?
> >         $connection = pg_connect("", "", "", "users");
> >         echo ("$connection");
> >         $query = "INSERT INTO users.login VALUES ( '$userindex', '$uname',
> >'$passwrd1', '1')";
> >         echo ("$query");
> >         $result = pg_exec ($connection, "select *");
> >         print (pg_cmdtuples($result));
> >         pg_close($connection);
> >?>
> >
> >This generates an error at the HTML output:
> >
> >1INSERT INTO login VALUES ( '1', 'test', 'test', '1');
> >Warning: PostgresSQL query failed: ERROR: login: Table does not exist. in
> >/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 6
> >
> >Warning: 0 is not a PostgresSQL result index in
> >/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 7
> >
> >
> >in the logffiles is specifies:
> >FindExec: found "/usr/local/postgres/bin/postgres" using argv[0]
> >started: host=localhost user=nobody database=users
> >InitPostgres
> >StartTransactionCommand
> >ERROR:  login: Table does not exist.
> >AbortCurrentTransaction
> >proc_exit(0) [#0]
> >shmem_exit(0) [#0]
> >exit(0)
> >/usr/local/postgres/bin/postmaster: reaping dead processes...
> >/usr/local/postgres/bin/postmaster: CleanupProc: pid 19113 exited with
> >status 0
> >
> >
> >I am a complete newby, so please go easy on me!
> >
> >Tnx!
> >Ramses
> >
> >
> >
> >
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com

Re: PHP-Postgres link

From
"omid omoomi"
Date:
Hi,
I didn't get what is the exact problem/error about the part of the php code.
May be you should explain more....
Any way, I had offen used pg_fetch_array function to get the data from the
tables. But If there is a sintax problem/error on your code,As I noticed,
may be you have to simply correct it by putting a ";" at the end of echo
instead of "."  like this :

echo pg_result($result, $i, "userindex") . " | " . pg_result($result, $i,
"username") . " | " .  pg_result($result, $i, "password") . " | "
.pg_result($result, $i, "field  4???") . " <BR> " ;


Hope that helps. Feel free to contact me .
Omid Omoomi



>From: Serj MD <root@ocher.pstu.ac.ru>
>To: pgsql-general@postgresql.org
>Subject: Re: [GENERAL] PHP-Postgres link
>Date: Wed, 12 Apr 2000 07:31:21 -0400
>
>Hello,
>I don't speak english, I'm sorry
>My example:
>
>$connection = pg_connect("", "", "", "users");
>$query = pg_exec($connection, "INSERT INTO login VALUES ( '$userindex',
>'$uname', '$password', '1')");
>$result = pg_exec ($connection, "select * from login");
>$num = pgNumRows($result);
>for($i = 0; $i < $num; $i++)
>{
>echo pg_result($result, $i, "userindex") . " | " . pg_result($result, $i,
>"username") . " | " .  pg_result($result, $i, "password") . " | "
>.pg_result($result, $i, "field  4???") . " <BR> " .
>}
>
>
>???????????????????????????????
>
>Best regards,
>Serj MD
>
> > Hi,
> > Do you still have your problem? Have you try this :
> > $query = "INSERT INTO login('$userindex' , '$uname','$passwrd1', '1')";
> >
> > Also "LOGIN" might be a reserved word, it would be better if you put
>another
> > name for your table.
> >
> >
> > Regards
> > Omid Omoomi
> >
> > >From: "Ramses v. Pinxteren" <ram6@euronet.nl>
> > >To: pgsql-general@postgresql.org
> > >Subject: [GENERAL] PHP-Postgres link
> > >Date: Sun, 9 Apr 2000 16:53:25 +0200
> > >
> > >Hi,
> > >
> > >I am running PHP under APache with a link to a postgres database. It
>gives
> > >me a headache because it is not working.
> > >
> > >I am running Apache as nobody, and I have made a Postgres user also
>named
> > >nobody.
> > >
> > >I made a postgres database users (as nobody: createdb users) and with
>psql
> > >a
> > >database login (field 1: userindex, field 2 username, field 3 password,
> > >field 4 security level)
> > >
> > >with psql i can do everything I want with this table. adding tuples,
> > >deleting them etc. etc.
> > >
> > >Now what do i need: I need a script that adds a new user to this
>database.
> > >so I created this:
> > ><?
> > >         $connection = pg_connect("", "", "", "users");
> > >         echo ("$connection");
> > >         $query = "INSERT INTO users.login VALUES ( '$userindex',
>'$uname',
> > >'$passwrd1', '1')";
> > >         echo ("$query");
> > >         $result = pg_exec ($connection, "select *");
> > >         print (pg_cmdtuples($result));
> > >         pg_close($connection);
> > >?>
> > >
> > >This generates an error at the HTML output:
> > >
> > >1INSERT INTO login VALUES ( '1', 'test', 'test', '1');
> > >Warning: PostgresSQL query failed: ERROR: login: Table does not exist.
>in
> > >/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 6
> > >
> > >Warning: 0 is not a PostgresSQL result index in
> > >/usr/local/apache/htdocs/isis.cx/database_update.php3 on line 7
> > >
> > >
> > >in the logffiles is specifies:
> > >FindExec: found "/usr/local/postgres/bin/postgres" using argv[0]
> > >started: host=localhost user=nobody database=users
> > >InitPostgres
> > >StartTransactionCommand
> > >ERROR:  login: Table does not exist.
> > >AbortCurrentTransaction
> > >proc_exit(0) [#0]
> > >shmem_exit(0) [#0]
> > >exit(0)
> > >/usr/local/postgres/bin/postmaster: reaping dead processes...
> > >/usr/local/postgres/bin/postmaster: CleanupProc: pid 19113 exited with
> > >status 0
> > >
> > >
> > >I am a complete newby, so please go easy on me!
> > >
> > >Tnx!
> > >Ramses
> > >
> > >
> > >
> > >
> >
> > ______________________________________________________
> > Get Your Private, Free Email at http://www.hotmail.com

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


Re: PHP-Postgres link

From
Serj MD
Date:
Hi,
I don't use pg_fetch_array. My english very bad and reading englesh documents
veri dificult for me. I use pg_result() and it is working. Look this:
<script language="php">
// Connect to database, select from table, etc...
$conn = pg_connect();
$result = pg_exec();
$num = pg_NumRows($result);

//Output to html-page
for($i=0; $i<$num; $i++)
{
    $userindex = pg_result($result, $i, "userindex");
    $username = pg_result($result, $i, "username");
    $password = pg_result($result, $i, "password");  // not good idea to my mind
    $field_4 = pg_result($result, $i, "field _4");
    echo "userindex: <i>$userindex</i>, username <i>$username</i>, password:<i>$password</i><br>";
}
</script>

It's worked. I don't have problem.

Best regards,
Serj MD


> Hi,
> I didn't get what is the exact problem/error about the part of the php code.
> May be you should explain more....
> Any way, I had offen used pg_fetch_array function to get the data from the
> tables. But If there is a sintax problem/error on your code,As I noticed,
> may be you have to simply correct it by putting a ";" at the end of echo
> instead of "."  like this :
>
> echo pg_result($result, $i, "userindex") . " | " . pg_result($result, $i,
> "username") . " | " .  pg_result($result, $i, "password") . " | "
> .pg_result($result, $i, "field  4???") . " <BR> " ;
>
>
> Hope that helps. Feel free to contact me .
> Omid Omoomi
>
>
>
> >From: Serj MD <root@ocher.pstu.ac.ru>
> >To: pgsql-general@postgresql.org
> >Subject: Re: [GENERAL] PHP-Postgres link
> >Date: Wed, 12 Apr 2000 07:31:21 -0400
> >
> >Hello,
> >I don't speak english, I'm sorry
> >My example:
> >
> >$connection = pg_connect("", "", "", "users");
> >$query = pg_exec($connection, "INSERT INTO login VALUES ( '$userindex',
> >'$uname', '$password', '1')");
> >$result = pg_exec ($connection, "select * from login");
> >$num = pgNumRows($result);
> >for($i = 0; $i < $num; $i++)
> >{
> >echo pg_result($result, $i, "userindex") . " | " . pg_result($result, $i,
> >"username") . " | " .  pg_result($result, $i, "password") . " | "
> >.pg_result($result, $i, "field  4???") . " <BR> " .
> >}
> >
> >
> >???????????????????????????????
> >
> >Best regards,
> >Serj MD