0
<?php
define('TYPO3_MODE','FE');

require('typo3conf/localconf.php');
require('t3lib/class.t3lib_db.php');
require('t3lib/class.t3lib_div.php');

define('TYPO3_db_host', $typo_db_host);
define('TYPO3_db_username', $typo_db_username);
define('TYPO3_db_password', $typo_db_password);
define('TYPO3_db', $typo_db);

define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME']))));
define('PATH_site', dirname(PATH_thisScript).'/');

$DB = new t3lib_DB();
$DB->connectDB();
...

问题:

在一个typo3自定义脚本中,我在上面看到了define(),但实际上在整个脚本中,并没有使用那些常量,例如TYPO3_MODTYPO3_db_host......为什么将它们define()放在脚本中?或者是typo3系统的要求,如果是这样,通常我们define()应该在脚本中放入什么?

4

1 回答 1

0

该类t3lib_DB使用常量来连接到用于typo3 的数据库。

/**
 * Connects to database for TYPO3 sites:
 *
 * @param string $host
 * @param string $user
 * @param string $password
 * @param string $db
 * @return  void
 */
function connectDB($host = TYPO3_db_host, $user = TYPO3_db_username, $password = TYPO3_db_password, $db = TYPO3_db) {
        // If no db is given we throw immediately. This is a sign for a fresh (not configured)
        // TYPO3 installation and is used in FE to redirect to 1-2-3 install tool
        ...

但这不是获得与数据库的连接的要求。您也可以直接将值传递给$DB->connectDB();

于 2013-07-17T07:32:16.893 回答