From: Dave VanAuken <dave@hawk-systems.com>
To: pgsql-php@postgresql.org
Subject: update after select doesn't update...
Date: Thu, 3 Jan 2002 00:29:48 -0500
Message-ID: <DBEIKNMKGOBGNDHAAKGNEELLLDAA.dave@hawk-systems.com> (raw)
Am retrieveing an "available" ipaddress from a table, then later trying to
perform an update to "assign" the address to an id. The update produces no
error, but doesn't update either. Must be overlooking something but can't place
a finger on it.
Table "host_ipaddress"
Attribute | Type | Modifier
-----------+---------+----------
server | text | not null
type | text |
hostnum | integer | not null
address | text |
Index: host_ipaddress_pkey
<?PHP
# Variables
$database = ***pg_connect statement***
$hostnum=2; # client reference number
$primipaddr=AssignPrivateIP($hostnum,'web'); #function returns IP address
# Function
function AssignPrivateIP($hostnumber,$server) {
global $database;
$query = "SELECT address FROM host_ipaddress WHERE server='$server' AND
type='private' AND hostnum=0 LIMIT 1";
$result = pg_exec($database,$query);
if(pg_numrows($result)==0) {
$return=0;
} else {
$row = pg_fetch_array($result,0);
$return=$row[0];
}
return $return;
}
# Queries
# following does not work, the hostnum in the database table stays at 0
$query="UPDATE host_ipaddress SET hostnum=$hostnum WHERE address='$primipaddr'";
# the following updates all records for the server/of type priv to 2
# **EXCEPT** the IP address we retrieved from the function (which we want to
update)
$query="UPDATE host_ipaddress SET hostnum=2 WHERE server='web' AND type='priv'";
...appropriate exec etc...
?>
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: dave@hawk-systems.com
Subject: Re: update after select doesn't update...
In-Reply-To: <DBEIKNMKGOBGNDHAAKGNEELLLDAA.dave@hawk-systems.com>
References: <DBEIKNMKGOBGNDHAAKGNEELLLDAA.dave@hawk-systems.com>
* 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