Forums

PHP

This topic is locked

Big problem with NULL field values and ADODB

Posted 01 Nov 2001 13:04:52
1
has voted
01 Nov 2001 13:04:52 Paul Groves posted:
Hi - I'm using the ADODB php library for my databse connections

I'm not sure if I'm missing something, but ADODB (I'm using version 1.40) seems to have a big problem when it encounters a field which has a value NULL.

An example - I want to display the prefix (e.g. Dr., Prof. etc.) and the name of people (where the prefix is a seperate field in the MySQL 3.23 database I'm retrieving the information from).

So the code I'm using is:
echo $PartDetail->Fields("prefix"
echo $PartDetail->Fields("first_name";
echo $PartDetail->Fields("last_name";

If a particular record has values for all these fields, all is well and the information displays correctly
However, not everyone uses a prefix, so this is often a NULL value. When this happens I get the error:
"Warning: Undefined index: prefix in D:\Inetpub\wwwroot\projects\adodb\adodb.inc.php on line 1363"
The line in question is:
return $this->fields[$colname];

If it was just a question of checking for a NULL value etc in my code before displaying, that wouldn't be a problem - but even trying to check the value of $PartDetail->Fields("prefix" throws up this error!

How are you meant to deal with NULL value fields in ADODB? The only way I can see to do it would be to edit the ADODB code, but that can't be right

Any help would be very much appreciated!

cheers

Paul

Replies

Replied 01 Nov 2001 13:34:17
01 Nov 2001 13:34:17 Bruno Mairlot replied:
You may want to use the <font color=red>IS NULL</font id=red> comparison operator.

In your query, where you select the field prefix, then just change it into :

SELECT <b>if(prefix IS NULL,"",prefix) as prefix</b>,first_name,last_name FROM ...

This way, you won't never have any NULL value in your rows. If the particular has no prefix, it won't be NULL but instead an empty string.

This way, you will not need to check the colname, just print the prefix, and if it has no prefix, nothing will be printed.

Don't know if this is going to solve your problem, but it's worth a try.

Bruno

--- Better to die trying, than never try at all ---

Reply to this topic