[TYPO3-dev] Stupid Stupid Stupid

Franz Holzinger franz at fholzinger.com
Tue Jun 24 09:49:38 CEST 2008


Hello Fr. Simon,

>  I freely admit to you all that I've not been good at coding extensions
> using the API, and this really basic and stupid question hopefully will mark
> a turn in that:
> 
> Previously, to extract data into an array, I would have written:
> 
>        $sql="SELECT * FROM ".$data["database"]." WHERE
> uid=".$data["drpRecordSelect"];
>        $newdata = $this->get_data($sql); // this is a function which queries
> and returns the array
> 
> and I know I should use exec_SELECTquery, so
> 
> global $TYPO3_DB;
> 
>         $newdata=$TYPO3_DB->exec_SELECTquery('*', $data["database"],
> 'uid='.$data["drpRecordSelect"], '', '', '');
> 
> so why isn't it returning anything? Am I not referencing the database object
> right (should it be $GLOBALS["TYPO3_DB"]) or is there something else
> fundamental in that.

See file t3lib/class.t3lib_db.php line 229 (TYPO3 4.2.1):

...
 * @return	pointer		MySQL result pointer / DBAL object
	 */
function
exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='')
{


So you should have written instead

$res=$TYPO3_DB->exec_SELECTquery('*',
data["database"],'uid='.intval($data["drpRecordSelect"]));
$newdata = $TYPO3_DB->sql_fetch_assoc($res);
$TYPO3_DB->sql_free_result($res);


Database is not a good key name for a database table array.

- Franz







More information about the TYPO3-dev mailing list