feel free to keep it strictly simple...

describe_table

method "describe_table"

Get detailed informations for the table-fields of a given db-table.
The result is also store in an array passed by reference.

@param 1: any valid given tablename incl. TABLE_PREFIX

@param 2: any valid array as a storage - pass by reference!

@param 3: optional one of the following constants

  • DESCRIBE_RAW
    - [or value 0] will store the filed infos as they are returned form the mysql-server
  • DESCRIBE_ASSOC
    - [or value 1] will store the result with the field "name" as assoc. array.
  • DESCRIBE_ONLY_NAMES
    - [or value 2] will only store the fieldnames in a linear array.

LEPTON_database::describe_table

Returns information about a given table

  1. $aInfo = [];
  2. LEPTON_database::getInstance()->describe_table(
  3. TABLE_PREFIX."mod_example",
  4. $aInfo,
  5. LEPTON_database::DESCRIBE_ASSOC
  6. );

Listing 2.1 :: describe_table

last edit: 08. Mar 2020 CET 12:04:39

 

A common use of this method is to test a given table for a existing field inside an upgrade-script: 

 

Example given:

  1. // Add database field "open"
  2. $fields = array();
  3. $database->describe_table(
  4. TABLE_PREFIX."mod_accordion",
  5. $fields,
  6. LEPTON_database::DESCRIBE_ONLY_NAMES
  7. );
  8. if (!in_array('open', $fields))
  9. {
  10. $database->simple_query(" ALTER TABLE ".TABLE_PREFIX."mod_accordion [...]
  11. }

Listing 2.2 :: describe_table

last edit: 08. Mar 2020 CET 11:42:04