[TYPO3-mvc] Query: Field names for table
Andrea Schmuttermair
abo at schmutt.de
Mon Apr 22 18:53:54 CEST 2013
Hello,
I try to get the field names from a given table in my extension.
The MySQL is:
"SHOW columns FROM mytable;" or
"SELECT column_name FROM information_schema.columns WHERE table_name =
'mytable';"
But I get always this exception:
http://www.schmutt.de/wp-content/uploads/exception.html
I thought setReturnRawQueryResult would prevent the automatic object
mapping. But looking at the Exception I think it tries to create a DataMap?
This is my repository function, both statements throw the exception:
/**
* get field names
* @param string $table tablename
* @return array field names
*/
public function getFieldNames($table) {
$query = $this->createQuery();
$query->getQuerySettings()->setReturnRawQueryResult(TRUE);
$query->statement('SHOW columns from '.$table);
//$query->statement('SELECT column_name FROM
information_schema.columns WHERE table_name = ?', array($table));
return $result = $query->execute();
}
Do you have any recommendation how to do this with Extbase? I am not
sure if queries like this are even possible?
This code is working, but not future proof:
$fields = array();
$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, 'SHOW columns from
'.$table);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$fields[] = $row['Field'];
}
return $fields;
Best regards,
Andrea
More information about the TYPO3-project-typo3v4mvc
mailing list