[TYPO3-mvc] Prepared statement with variable num of arguments?
Xavier Perseguers
xavier at typo3.org
Fri Oct 25 13:58:50 CEST 2013
Hi,
> I have a scenario where I whish to generate SQL queries dynamically but
> also like to benefit from prepared statements.
>
> When using prepared statements one has to specify the values to be
> inserted directly within the method call:
>
> $query->statement(
> 'select * from tbl_foo where foo=? and bar=?',
> 'fooVal',
> 'barVal'
> );
>
> As my sql is generated in a dynamic way I wonder if there is a way to
> deal with the variable number of parameters like this:
>
> // $values would be an array, $sql a string
> list($sql,$values) = $this->createSqlAndValues($mySearchParams);
> $query->statement($sql,$values);
>
> Any ideas on how to deal with this scenario?
The original preparedstatement introduced in TYPO3 4.5 let you separate
the SQL definition and the execution with a given set of "values":
http://buzz.typo3.org/teams/core/article/typo3-45-lts-prepared-queries-are-the-way-to-go/
--
Xavier Perseguers
Release Manager TYPO3 4.6
TYPO3 .... inspiring people to share!
Get involved: http://typo3.org
More information about the TYPO3-project-typo3v4mvc
mailing list