global variable problem

From: "Jules Alberts" <jules(dot)alberts(at)arbodienst-limburg(dot)nl>
To: pgsql-php(at)postgresql(dot)org
Subject: global variable problem
Date: 2002-04-22 13:43:48
Message-ID: 200204221416.g3MEG1R0025391@artemis.cuci.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

hi everybody,

i'm making a little testscript that uses adodb to connect via PHP4 to a
postgresql 7.2 db. something like this:

=== file index.php ===
<?php
include_once('adodb/adodb.inc.php');
$conn=ADONewConnection('postgres7');
if (@$conn->PConnect('localhost','username', 'password', 'dbname')) {
include("show.php");
}
?>
=== eof ==============

=== file show.php ===
<?php
switch ($action) {
case start:
start();
break;
case listing:
listing($bereik);
break;
default:
start();
break;
}

function start() {
global $conn;
echo "<h2>Choose a letter</h2>\n";
$lett=array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
foreach ($lett as $i) {
echo "\n\t<a href='show.php?action=listing&range=$i'>$i</a> ";
}
}

function listing($range) {
global $conn;
echo "<h2>Range: ", $range, "</h2>\n";
$rs=$conn->Execute("select * from rolo where name like '$range%'");
}
?>
=== eof ==============

that's all. the idea is that the users clicks a letter, the function
listing() is called, and a selection is made. the problem is the
visibility of $conn. it's visible in index.php and in start(), but in
listing() it's gone!?! the line $rs=$conn->exectute in listing()
produces an error "call to a member of a non-object".

what am i doing wrong? how do i make $conn visible in listing()? TIA
for any pointers / help!

--
Jules Alberts

Browse pgsql-php by date

  From Date Subject
Next Message Ruben Vivas 2002-04-22 20:18:45 RV: calling a pl/pgsql function with array in argument
Previous Message Maxim Maletsky (PHPBeginner.com) 2002-04-22 13:17:19 Re: