Re: More on functions
| From: | Alexander Wagner | Date: | Sun, 07 Jan 2001 19:48:35 +0000 |
| Subject: | Re: More on functions | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-33112@lists.php.net to get a copy of this message | ||
Abe wrote:
> function DatabaseConnect()
> {
> global $connection;
> $connection = pg_connect("dbname=abe port=5435") or die ("Couldn't
> make a connection.");
> }
>
> DatabaseConnect();
> $sql = "select firstname etc etc etc etc ....";
> $sql_result = pg_exec($connection,$sql);
I can't see anything wrong (I never used pg_*(), by the way). However,
this kind of handling variables is bad style and makes debugging
difficult. You should do it this way:
function DatabaseConnect()
{
$connection = pg_connect("dbname=abe port=5435") or die ("foobar");
return $connection;
}
$connection = DatabaseConnect();
$sql_query = "select firstname etc etc etc etc ....";
$sql_result = pg_exec($connection,$sql_query);
For debugging, you could try to echo $connection.
Wagner
--
Sanity is calming, but madness is more interesting.