the_oliver Posted October 1, 2006 Share Posted October 1, 2006 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 29Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL result resource in /var/www/html/helm-associates.net/parts/common.php on line 31Code: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. Link to comment https://forums.phpfreaks.com/topic/22678-pg_query/ Share on other sites More sharing options...
printf Posted October 1, 2006 Share Posted October 1, 2006 change this...[code]function is_auth_approved(){[/code]to this...[code]function is_auth_approved(){ global $pg_connection;[/code]orpass the connection resource to the function![code]$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);}[/code]me! Link to comment https://forums.phpfreaks.com/topic/22678-pg_query/#findComment-101961 Share on other sites More sharing options...
the_oliver Posted October 1, 2006 Author Share Posted October 1, 2006 :) knew it would be simple! Thanks Link to comment https://forums.phpfreaks.com/topic/22678-pg_query/#findComment-101976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.