Re: Warning: Supplied argument is not a valid PostgreSQL link resource

Поиск
Список
Период
Сортировка
От Nick Barr
Тема Re: Warning: Supplied argument is not a valid PostgreSQL link resource
Дата
Msg-id 8F4A22E017460A458DB7BBAB65CA6AE5027B75@webbased9.wb9.webbased.co.uk
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: victor moran
Дата:
Сообщение: Hosting a data file on a SAN
Следующее
От: "Jan Gravgaard"
Дата:
Сообщение: Re: Warning: Supplied argument is not a valid PostgreSQL link resource