[TYPO3-core] RFC #15457: Add support for prepared queries
Xavier Perseguers
typo3 at perseguers.ch
Thu Aug 19 12:18:16 CEST 2010
Hi,
> ok, even when i change it to $stmt->execute(array(':pid' => 2)); it 's
> wrong sql, parameter isn't replaced.
Yes, you wrote ":uid" in SQL but replaced ":pid", not the same parameter...
I may throw an exception if one tries to replace an non-existing
parameter but the point is the information is not available when not
using the parser. As such the exception you got from MySQL DBMS is
correct, the query was actually wrong!
> testin 2nd example:
>
> $content = '';
> $stmt = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('uid, title', 'pages',
> 'pid = ?');
> $pid = 1;
> $stmt->bindParam(1, $pid);
> $stmt->execute();
> $pagesWithPid1 = $stmt->fetchAll();
> $stmt->free();
>
> $pid = 4;
> $stmt->execute();
> $pagesWithPid4 = $stmt->fetchAll();
> $stmt->free();
> return t3lib_div::view_array($pagesWithPid1) .
> t3lib_div::view_array($pagesWithPid4);
>
> i get
> Fatal error: Call to undefined method
> t3lib_db_PreparedStatement::bindParam() in
> C:\xampp\htdocs\tv\typo3conf\ext\tester\mod1\index.php on line 184
>
> please provide some examples work with this patch ;)
Please have a look at tests from my latest post. bindParam() is not
available anymore as we agreed that it was not a good programming style.
So even if PDO allows and provides this feature, we removed it from our
implementation as it only makes sense when queries might "write back"
something.
Public methods are available through phpDoc but in short:
->bindValue()
->bindValues(array())
->execute(array())
Cheers
Xavier
More information about the TYPO3-team-core
mailing list