[TYPO3-core] RFC #15457: Add support for prepared queries

Steffen Kamper info at sk-typo3.de
Thu Aug 19 14:36:43 CEST 2010


Hi Xavier,

Xavier Perseguers schrieb:
> Hi,
> 
> Here is v5 in order to have the version that (should) be committed 
> present in this list.
> 

+1 by reading and testing now.
Tested these 3 methods:

#1 binding in execute (only work with ? !!!)
* one parameter
$stmt = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'pages', 'pid = ?');
$stmt->execute(array(2));
while (($row = $stmt->fetch()) !== FALSE) {
	$content .= t3lib_div::view_array($row);
}
$stmt->free();

* 2 parameters
$stmt = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'pages', 'pid = ? 
AND uid > ?');
$stmt->execute(array(2, 2));
while (($row = $stmt->fetch()) !== FALSE) {
	$content .= t3lib_div::view_array($row);
}
$stmt->free();

#2 bindValue
* one parameter
$statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('uid, title', 
'pages', 'pid = :pid');
$statement->bindValue(':pid', 2);
$statement->execute();
$content .= t3lib_div::view_array($statement->fetchAll());
$statement->free();

* 2 parameters
$statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('uid, title', 
'pages', 'pid = :pid AND uid > :uid');
$statement->bindValue(':pid', 2)->bindValue(':uid', 2);
$statement->execute();
$content .= t3lib_div::view_array($statement->fetchAll());
$statement->free();

#3 bindValues
$statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('uid, title', 
'pages', 'pid = :pid AND uid > :uid');
$statement->bindValues(array(':pid' => 2, ':uid' => 2));
$statement->execute();
$content .= t3lib_div::view_array($statement->fetchAll());
$statement->free();

#4 bindValues with no named parameters
$statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('uid, title', 
'pages', 'pid = ? AND uid > ?');
$statement->bindValues(array(2, 2));
$statement->execute();
$content .= t3lib_div::view_array($statement->fetchAll());
$statement->free();

excellent! Ready for commit.

vg Steffen


More information about the TYPO3-team-core mailing list