Jump to content


Photo

pg_query


  • Please log in to reply
2 replies to this topic

#1 the_oliver

the_oliver
  • Members
  • PipPipPip
  • Advanced Member
  • 364 posts
  • LocationSurrey, UK

Posted 01 October 2006 - 06:38 PM

Hi all!
Having a problem trying to poll a postgresql database.
Im running the code below, and get the following two error: (wrong line numbers!)

Warning: pg_query(): supplied argument is not a valid PostgreSQL link resource in /var/www/html/helm-associates.net/parts/common.php on line 29

Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL result resource in /var/www/html/helm-associates.net/parts/common.php on line 31


Code:


function is_auth_approved()
        {
        $ip=$_SERVER['REMOTE_ADDR'];

        $query = "SELECT ip FROM member WHERE session = '".session_id()."'";
        $result = pg_query($pg_connection,  $query);

        $count_rows = pg_num_rows($result);

        if ($count_rows > 0)
                {
                for ($i=0; $i<$count_rows; $i++)
                        {
                        $row = pg_fetch_row($result, $i);
                        if ( $row[0] == $ip )
                                {
                                return "1";
                                }
                        else
                                {
                                return "0";
                                }
                        }
                }
                else
                {
                return "0";
                }
}
pg_close($pg_connection);


With connection details in a nother file as follows:

//FOR CONNECTION TO POSTGRESQL DATABASE
$pg_host = "hostdetails";
$pg_user = "username";
$pg_pass = "password";
$pg_db  = "helm_associates";
$pg_connection = pg_connect ("host=$pg_host dbname=$pg_db user=$pg_user password=$pg_pass");
        if (!$pg_connection)
          {
          die("Could not open connection to database server $pg_host");
          }


Sure its just something simple ive missed but not sure what! Thanks.

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 01 October 2006 - 07:23 PM

change this...

function is_auth_approved()
{

to this...

function is_auth_approved()
{
	global $pg_connection;

or

pass the connection resource to the function!


$test = is_auth_approved ( $pg_connection );

function is_auth_approved ( $con )
{
        $ip=$_SERVER['REMOTE_ADDR'];

        $query = "SELECT ip FROM member WHERE session = '".session_id()."'";
        $result = pg_query($con,  $query);
}


me!

#3 the_oliver

the_oliver
  • Members
  • PipPipPip
  • Advanced Member
  • 364 posts
  • LocationSurrey, UK

Posted 01 October 2006 - 08:12 PM

:) knew it would be simple! Thanks






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users