Re: Warning: Supplied argument is not a valid PostgreSQL link resource - Mailing list pgsql-general

From Nick Barr
Subject Re: Warning: Supplied argument is not a valid PostgreSQL link resource
Date
Msg-id 8F4A22E017460A458DB7BBAB65CA6AE5027B75@webbased9.wb9.webbased.co.uk
Whole thread Raw
List pgsql-general
Hi,

>      function sql_execute($query)
>      {
>  $resultat = pg_exec($conn, $query);
>
>           if(!$resultat) {
>       echo "Kunne ikke udføre: <em>$query</em>";
>       return;
>    }
>      }

You are missing the global $conn in the function. You either need to feed it in as a parameter or reference it as a
globalvariable. 

function sql_execute($conn, $query)
{
    $resultat = pg_exec($conn, $query);
    if(!$resultat)
    {
        echo "Kunne ikke udføre: <em>$query</em>";
        return;
    }
}

OR

function sql_execute($query)
{
    global $conn;

    $resultat = pg_exec($conn, $query);
    if(!$resultat)
    {
        echo "Kunne ikke udføre: <em>$query</em>";
        return;
    }
}

This is the same for the sql_execute_receive, conn_close and any other function that references $conn. PHP does not
automaticallyinclude global variables in the functions scope. 

I currently set $conn to be a global variable (i.e. declared outside the function) and use the global $conn method to
getit into scope with the function. 

Hope that's a little clearer.

Nick Barr

pgsql-general by date:

Previous
From: victor moran
Date:
Subject: Hosting a data file on a SAN
Next
From: "Jan Gravgaard"
Date:
Subject: Re: Warning: Supplied argument is not a valid PostgreSQL link resource