简体   繁体   English

使用typo3中的函数更新查询

[英]update query with functions in typo3

I'm trying to use the typo3 update function with the mysql CONCAT function. 我正在尝试将typo3更新功能与mysql CONCAT函数一起使用。 Can you tell me how to manage that? 你能告诉我如何处理吗? What I tried: 我试过的

$updateArray = array("field" => 'CONCAT( field'.','.$toAppend.')');
$GLOBALS['TYPO3_DB']->exec_UPDATEquery ('table','id = '.'"'.$some_id.'"',$updateArray);

That does not work, because that query is executed: 那是行不通的,因为执行了该查询:

UPDATE table
SET
pagesEdited='CONCAT( field,'value')'
WHERE
id = "id"

As you see, the concat function is escaped. 如您所见, concat函数已转义。

The reference documentation isn't very clear about it, however, just appending TRUE to your parameters of the update function should disable quoting: 参考文档对此不太清楚,但是,仅将TRUE附加到更新函数的参数中应会禁用引号:

$GLOBALS['TYPO3_DB']->exec_UPDATEquery ('table','id = '.'"'.$some_id.'"',$updateArray, TRUE);

That also means that you will have to do your own input sanitization before lauching the query, if you haven't already: 这还意味着,如果尚未启动查询,则必须在启动查询之前进行自己的输入清理:

$toAppend = $GLOBALS['TYPO3_DB']->fullQuoteString($toAppend, "");

Have a look at the noQuote parameter of the fullQuoteArray() method of TYPO3\\CMS\\Core\\Database\\DatabaseConnection that is used by exec_UPDATEquery() : 看一看在noQuote的参数fullQuoteArray()的方法TYPO3\\CMS\\Core\\Database\\DatabaseConnection所使用的exec_UPDATEquery()

@param boolean|array $noQuote List/array of keys NOT to quote (eg. SQL functions) - ONLY for associative arrays

And when you take a kloser look ath this method, you will see that a simple true does not do the trick as expected. 当您使用这种方法查看kloser时,您会发现简单的true并不能达到预期的效果。 Simply use a list of fields (comma separated list) or an array to let TYPO3 know which fields should not be escaped. 只需使用一个字段列表(用逗号分隔的列表)或一个数组,让TYPO3知道哪些字段不应转义。

In your case it would look like this: 在您的情况下,它看起来像这样:

$updateArray = array(
    'field' => 'CONCAT(field,' . $GLOBALS['TYPO3_DB']->fullQuoteString($toAppend, 'table') . ')',
);
$where = 'id = ' . $GLOBALS['TYPO3_DB']->fullQuoteString($some_id, 'table');

$GLOBALS['TYPO3_DB']->exec_UPDATEquery ('table', $where, $updateArray, 'field');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM