[TYPO3-english] db tables and field names

Xavier Perseguers typo3 at perseguers.ch
Mon Jan 3 15:07:26 CET 2011


Hi,

Katja Lampela wrote:
> ..and I know that with the WEB/List module (Set fields select box) I can
> set the fields to be seen in the list. But I would need the field names
> also, the excact names of the database fields.

Just use a "describe" or a "show columns from" statement (example from 
mysql command line but the same applies with TYPO3_DB API with a simple 
query:

mysql> describe fe_users;
+------------------+---------------------+------+-----+---------+----------------+
| Field            | Type                | Null | Key | Default | Extra 
          |
+------------------+---------------------+------+-----+---------+----------------+
| uid              | int(11) unsigned    | NO   | PRI | NULL    | 
auto_increment |
| pid              | int(11) unsigned    | NO   | MUL | 0       | 
          |
| tstamp           | int(11) unsigned    | NO   |     | 0       | 
          |
| username         | varchar(50)         | NO   | MUL |         | 
          |
| password         | varchar(40)         | NO   |     |         | 
          |
| usergroup        | tinytext            | YES  |     | NULL    | 
          |
| disable          | tinyint(4) unsigned | NO   |     | 0       | 
          |
| starttime        | int(11) unsigned    | NO   |     | 0       | 
          |
| endtime          | int(11) unsigned    | NO   |     | 0       | 
          |
| name             | varchar(80)         | NO   |     |         | 
          |
| address          | varchar(255)        | YES  |     |         | 
          |
| telephone        | varchar(20)         | NO   |     |         | 
          |
| fax              | varchar(20)         | NO   |     |         | 
          |
| email            | varchar(80)         | NO   |     |         | 
          |
| crdate           | int(11) unsigned    | NO   |     | 0       | 
          |
| cruser_id        | int(11) unsigned    | NO   |     | 0       | 
          |
| lockToDomain     | varchar(50)         | NO   |     |         | 
          |
| deleted          | tinyint(3) unsigned | NO   |     | 0       | 
          |
| uc               | blob                | NO   |     | NULL    | 
          |
| title            | varchar(40)         | NO   |     |         | 
          |
| zip              | varchar(10)         | NO   |     |         | 
          |
| city             | varchar(50)         | NO   |     |         | 
          |
| country          | varchar(40)         | NO   |     |         | 
          |
| www              | varchar(80)         | NO   |     |         | 
          |
| company          | varchar(80)         | NO   |     |         | 
          |
| image            | tinytext            | YES  |     | NULL    | 
          |
| TSconfig         | text                | YES  |     | NULL    | 
          |
| fe_cruser_id     | int(10) unsigned    | NO   |     | 0       | 
          |
| lastlogin        | int(10) unsigned    | NO   |     | 0       | 
          |
| is_online        | int(10) unsigned    | NO   | MUL | 0       | 
          |
| tx_openid_openid | varchar(255)        | NO   |     |         | 
          |
| first_name       | varchar(50)         | NO   |     |         | 
          |
| middle_name      | varchar(50)         | NO   |     |         | 
          |
| last_name        | varchar(50)         | NO   |     |         | 
          |
+------------------+---------------------+------+-----+---------+----------------+
34 rows in set (0.00 sec)


The other solution is to use TYPO3's API. If you have a look at t3lib_DB 
(as you know available through $GLOBALS['TYPO3_DB']):

  *			  SECTION: SQL admin functions
  *  947:	 function admin_get_dbs()
  *  965:	 function admin_get_tables()
  *  984:	 function admin_get_fields($tableName)
  * 1002:	 function admin_get_keys($tableName)
  * 1020:	 function admin_query($query)

What I did manually is exactly what

$GLOBALS['TYPO3_DB']->admin_get_fields('fe_users');

does...

Cheers
Xavier


More information about the TYPO3-english mailing list