From: Jules Alberts <jules.alberts@arbodienst-limburg.nl>
To: pgsql-php@postgresql.org
Subject: global variable problem
Date: Mon, 22 Apr 2002 15:43:48 +0200
Message-ID: <200204221416.g3MEG1R0025391@artemis.cuci.nl> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: jules.alberts@arbodienst-limburg.nl
Subject: Re: global variable problem
In-Reply-To: <200204221416.g3MEG1R0025391@artemis.cuci.nl>
References: <200204221416.g3MEG1R0025391@artemis.cuci.nl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox