13.4. Reading data from a database
Prev | Chapter 13. Getting hold of the data to be displayed | Next

## 13.4. Reading data from a database

Since there are so many databases and so many ways to organize data in tables it is impossible to give generic examples. Instead we point out some common pitfalls when gathering data from a database.

- Make sure the data is valid numeric data. It is a common mistake to read `NULL` (or empty strings "") values and try to plot them. Beware that the PHP function `empty()` also will return true for 0 and "0" values so it is not enough to just test with `empty()` since this will also remove all values that happens to be valid 0 values. To avoid this use the following modified empty method.

      1
      2
      3
      4
      5

      function empty0($aValue){
          if ( !is_numeric(trim($aValue)) )
              return empty($aValue);
          return false;
      }

- Some databases (e.g. MySQL) returns a column with decimal type values as string in a SELECT statement which normally is handled by automatic conversion in PHP but since PHP has different interpretation of "0.00" and 0.00 in respect to what is interpreted as empty or not this needs to be carefully handled.

Prev | Up | Next
13.3. Sending data to a graph script with URI arguments (GET and POST) | Home | 13.5. Reading binary data from a file