Checking for NULL value in Database
| From: | Andre Dubuc | Date: | Mon, 17 Jun 2002 14:46:27 +0000 |
| Subject: | Checking for NULL value in Database | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102518@lists.php.net to get a copy of this message | ||
I'm tryiing to append entries in a db textarea field 'rbook'. Everything
works fine IF there is an existing entry. However, if no entries exist, it
nothing is written to the db. (PostgreSQL 7.2)
How do you check for null value of a PostgreSQl db field? Here's what I've
tried:
*************************************************************************************
/* Update db with 'rbook' . Check if prior entries exist, and add to end of
string, separate with '@' . If no entries (db entry is NULL value), then set
'rbook' = $_SESSION['rbook'] */
$db = pg_connect("dbname=rose user=postgres");
$query = "SELECT rbook FROM rap WHERE rid = '{$_SESSION['rid']}'";
$result = pg_exec($db, $query);
if ($result == NULL){
$db = pg_connect("dbname=rose user=postgres");
$query = "UPDATE rap SET rbook = '{$_SESSION['rbook']}' WHERE rid
= '{$_SESSION['rid']}'";
$result = pg_exec($db, $query);
if (!$result) {exit;}
pg_close($db);
}
else
{
$db = pg_connect("dbname=rose user=postgres");
$query = "UPDATE rap SET rbook = rbook ||'@ {$_SESSION['rbook']}' WHERE
rid
= '{$_SESSION['rid']}'";
$result = pg_exec($db, $query);
if (!$result) {exit;}
pg_close($db);
}
*****************************************************************************************
I think the problem occurs in my formulation of "if($result == NULL)". I've
scoured the archives for this problem, and found only references to
"if(!isset(........)){do something};" I'm not sure whether I can use this
with a db query??
Any suggestions or advice will be greatly appreciated. I'm stumped.
Tia,
Andre
--
Please pray the Holy Rosary to end the holocaust of abortion.
Remember in your prayers the Holy Souls in Purgatory.
May God bless you abundantly in His love!
For a free Cenacle Scriptural Rosary Booklet: http://www.webhart.net/csrb/