<?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_MOD
,TYPO3_db_host
这些常量...为什么要放这些{脚本中的{1}}?或者它是typo3系统的要求,如果是这样,通常我们应该将define()
放入脚本中?
答案 0 :(得分: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();