TYPO3 v7: Extbase createQuery()->statement() with variables

raw

README.rst

Error message when not using the prepared statement class:

#1247602160: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? LIMIT 1' at line 8 (More information)

Source: https://typo3-german.typo3.narkive.com/kGx9nVtN/prepared-statements-in-extbase-typo3-7-6#post5

raw

typo3v7-extbase-statement.php

1
2
3
4
5
6
7
8
9
10
11
$query = $this->createQuery();                                   
$query = $query->statement(
    //manually creating PreparedStatement should not be necessary
    //anymore in typo3 v8+
    new \TYPO3\CMS\Core\Database\PreparedStatement(              
        'SELECT * FROM tablename WHERE col = ? LIMIT 1',
        'tablename'
    ),
    ['myvalue']
);
$result = $query->execute();
Christian Weiske Christian Weiske
owner

History