Thread: can't retrieve data through PHP

can't retrieve data through PHP

From
Bruce Young
Date:
my script that does insert works correctly, but i get this error when
retrieving data:

Warning: pg_exec(): supplied argument is not a valid PostgreSQL link
resource in /home/httpd/htdocs/view.php on line 115

Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL
result resource in /home/httpd/htdocs/view.php on line 118

i am using postgreSQL 7.2.3, php/mod_php 4.2.2 on Gentoo Linux.

  - bruce

__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

Re: can't retrieve data through PHP

From
dan radom
Date:
* Bruce Young (hbrucey@yahoo.com) wrote:
> my script that does insert works correctly, but i get this error when
> retrieving data:
>
> Warning: pg_exec(): supplied argument is not a valid PostgreSQL link
> resource in /home/httpd/htdocs/view.php on line 115
>
> Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL
> result resource in /home/httpd/htdocs/view.php on line 118
>

how about showing us the connection and query parts of view.php

dan

Re: can't retrieve data through PHP

From
Bruce Young
Date:
php connection query:

<?php
        #include('DB/pgsql.php');

    $dbconnect = pg_connect("dbname=campus user=apache");


    $result = pg_exec ($conn, "select * from friends");
    if (!result) {printf ("Error\n"); exit;}

    $numrows = pg_num_rows($result);

    for ($i=0; $i < $numrows; $i++) {
       $r = pg_fetch_row($result, $i);

       for ($j=0; $j < count($r); $j++) {
          echo "$r[$j] ";
       }
       echo "<br>";
       }
    pg_close($dbconnect);
?>


--- dan radom <dan@radom.org> wrote:
> * Bruce Young (hbrucey@yahoo.com) wrote:
> > my script that does insert works correctly, but i get this error
> when
> > retrieving data:
> >
> > Warning: pg_exec(): supplied argument is not a valid PostgreSQL
> link
> > resource in /home/httpd/htdocs/view.php on line 115
> >
> > Warning: pg_num_rows(): supplied argument is not a valid
> PostgreSQL
> > result resource in /home/httpd/htdocs/view.php on line 118
> >
>
> how about showing us the connection and query parts of view.php
>
> dan
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister
> command
>     (send "unregister YourEmailAddressHere" to
majordomo@postgresql.org)


__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

Re: can't retrieve data through PHP

From
Chadwick Rolfs
Date:
Your variables don't match.  And your coding is very inconsistent.  The if
construct should follow the for construct.  It makes everything READABLE
and understandable.
Good luck

On Sat, 26 Oct 2002, Bruce Young wrote:

> php connection query:
>
> <?php
>         #include('DB/pgsql.php');
>
>     $dbconnect = pg_connect("dbname=campus user=apache");

HERE YOU HAVE DBCONNECT

>
>
>     $result = pg_exec ($conn, "select * from friends");

HERE YOU HAVE CONN

>     if (!result) {printf ("Error\n"); exit;}
>
>     $numrows = pg_num_rows($result);
>
>     for ($i=0; $i < $numrows; $i++) {
>        $r = pg_fetch_row($result, $i);
>
>        for ($j=0; $j < count($r); $j++) {
>           echo "$r[$j] ";
>        }
>        echo "<br>";
>        }
>     pg_close($dbconnect);
> ?>
>
>
> --- dan radom <dan@radom.org> wrote:
> > * Bruce Young (hbrucey@yahoo.com) wrote:
> > > my script that does insert works correctly, but i get this error
> > when
> > > retrieving data:
> > >
> > > Warning: pg_exec(): supplied argument is not a valid PostgreSQL
> > link
> > > resource in /home/httpd/htdocs/view.php on line 115
> > >
> > > Warning: pg_num_rows(): supplied argument is not a valid
> > PostgreSQL
> > > result resource in /home/httpd/htdocs/view.php on line 118
> > >
> >
> > how about showing us the connection and query parts of view.php
> >
> > dan
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister
> > command
> >     (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
>
>
> __________________________________________________
> Do you Yahoo!?
> Y! Web Hosting - Let the expert host your web site
> http://webhosting.yahoo.com/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>

-Chadwick


Re: can't retrieve data through PHP

From
Bruce Young
Date:
thanks guys for the quick response and tips.
everything works well now. dont know how i didnt catch that one.. :)

  - bruce

--- Chadwick Rolfs <cmr@shell.gis.net> wrote:
> Your variables don't match.  And your coding is very inconsistent.
> The if
> construct should follow the for construct.  It makes everything
> READABLE
> and understandable.
> Good luck
>
> On Sat, 26 Oct 2002, Bruce Young wrote:
>
> > php connection query:
> >
> > <?php
> >         #include('DB/pgsql.php');
> >
> >     $dbconnect = pg_connect("dbname=campus user=apache");
>
> HERE YOU HAVE DBCONNECT
>
> >
> >
> >     $result = pg_exec ($conn, "select * from friends");
>
> HERE YOU HAVE CONN
>
> >     if (!result) {printf ("Error\n"); exit;}
> >
> >     $numrows = pg_num_rows($result);
> >
> >     for ($i=0; $i < $numrows; $i++) {
> >        $r = pg_fetch_row($result, $i);
> >
> >        for ($j=0; $j < count($r); $j++) {
> >           echo "$r[$j] ";
> >        }
> >        echo "<br>";
> >        }
> >     pg_close($dbconnect);
> > ?>
> >
> >
> > --- dan radom <dan@radom.org> wrote:
> > > * Bruce Young (hbrucey@yahoo.com) wrote:
> > > > my script that does insert works correctly, but i get this
> error
> > > when
> > > > retrieving data:
> > > >
> > > > Warning: pg_exec(): supplied argument is not a valid
> PostgreSQL
> > > link
> > > > resource in /home/httpd/htdocs/view.php on line 115
> > > >
> > > > Warning: pg_num_rows(): supplied argument is not a valid
> > > PostgreSQL
> > > > result resource in /home/httpd/htdocs/view.php on line 118
> > > >
> > >
> > > how about showing us the connection and query parts of view.php
> > >
> > > dan
> > >
> > > ---------------------------(end of
> > > broadcast)---------------------------
> > > TIP 2: you can get off all lists at once with the unregister
> > > command
> > >     (send "unregister YourEmailAddressHere" to
> > majordomo@postgresql.org)
> >
> >
> > __________________________________________________
> > Do you Yahoo!?
> > Y! Web Hosting - Let the expert host your web site
> > http://webhosting.yahoo.com/
> >
> > ---------------------------(end of
> broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister
> command
> >     (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
> >
>
> -Chadwick
>


__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

Re: can't retrieve data through PHP

From
Chadwick Rolfs
Date:
A better way to to db connection (without extra modules or anything),
would be to make a small .php file with your connect command in it.  Then
you include that file in each of your scripts that need it (probably at
the top, or whereever).  This may eliminate the need to make a new
connection, since your actual connect script never changes.  It also
drastically reduces errors, and if put into a non-web findable directory
(but it has to be readable by the web-server/php), it can be far more
secure.

Take care.  If anything above is misinformation, please correct me :>

On Sat, 26 Oct 2002, Bruce Young wrote:

> thanks guys for the quick response and tips.
> everything works well now. dont know how i didnt catch that one.. :)
>
>   - bruce
>
> --- Chadwick Rolfs <cmr@shell.gis.net> wrote:
> > Your variables don't match.  And your coding is very inconsistent.
> > The if
> > construct should follow the for construct.  It makes everything
> > READABLE
> > and understandable.
> > Good luck
> >
> > On Sat, 26 Oct 2002, Bruce Young wrote:
> >
> > > php connection query:
> > >
> > > <?php
> > >         #include('DB/pgsql.php');
> > >
> > >     $dbconnect = pg_connect("dbname=campus user=apache");
> >
> > HERE YOU HAVE DBCONNECT
> >
> > >
> > >
> > >     $result = pg_exec ($conn, "select * from friends");
> >
> > HERE YOU HAVE CONN
> >
> > >     if (!result) {printf ("Error\n"); exit;}
> > >
> > >     $numrows = pg_num_rows($result);
> > >
> > >     for ($i=0; $i < $numrows; $i++) {
> > >        $r = pg_fetch_row($result, $i);
> > >
> > >        for ($j=0; $j < count($r); $j++) {
> > >           echo "$r[$j] ";
> > >        }
> > >        echo "<br>";
> > >        }
> > >     pg_close($dbconnect);
> > > ?>
> > >
> > >
> > > --- dan radom <dan@radom.org> wrote:
> > > > * Bruce Young (hbrucey@yahoo.com) wrote:
> > > > > my script that does insert works correctly, but i get this
> > error
> > > > when
> > > > > retrieving data:
> > > > >
> > > > > Warning: pg_exec(): supplied argument is not a valid
> > PostgreSQL
> > > > link
> > > > > resource in /home/httpd/htdocs/view.php on line 115
> > > > >
> > > > > Warning: pg_num_rows(): supplied argument is not a valid
> > > > PostgreSQL
> > > > > result resource in /home/httpd/htdocs/view.php on line 118
> > > > >
> > > >
> > > > how about showing us the connection and query parts of view.php
> > > >
> > > > dan
> > > >

-Chadwick