首页 > 解决方案 > TYPO3 - Scheduler task with custom query

问题描述

I'm using TYPO3 6.2. I created a custom Extbase Task in order to execute it automatically every day.

<?php

namespace Myextension\Scheduler;

use TYPO3\CMS\Core\Utility\GeneralUtility;

class Task extends \TYPO3\CMS\Scheduler\Task\AbstractTask {


    public function execute()
    {

        // Custom MySQL query here

    }

}

?>

I need to develop a complicated mysql query with a lot of conditions, datas and joins : is it possible not to use $GLOBALS['TYPO3_DB']->exec_SELECTquery but a method like $GLOBALS['TYPO3_DB']->sql_query(' SELECT * FROM ... ') ?

标签: typo3extbasetypo3-6.2.x

解决方案


Yes, that's definitely possible.

This is the complete function:

/**
 * Executes query
 * MySQLi query() wrapper function
 * Beware: Use of this method should be avoided as it is experimentally supported by DBAL. You should consider
 * using exec_SELECTquery() and similar methods instead.
 *
 * @param string $query Query to execute
 * @return boolean|\mysqli_result|object MySQLi result object / DBAL object
 */
public function sql_query($query) {
    $res = $this->query($query);
    if ($this->debugOutput) {
        $this->debug('sql_query', $query);
    }
    return $res;
}

And you find it in the file:

typo3/sysext/core/Classes/Database/DatabaseConnection.php

And you can call it like you wrote:

$GLOBALS['TYPO3_DB']->sql_query(' SELECT * FROM ... ') 

推荐阅读