简体   繁体   中英

TYPO3 6.2 PHP script database connection

I should do an Upgrade to TYPO3 6.2. In some old extension there are several php scripts which are directly called by an URL. In those scripts they build a database connection in the following way

define ('PATH_t3lib','t3lib/'); 
require_once('../../../t3lib/class.t3lib_db.php');
require_once('../../../t3lib/class.t3lib_div.php');
require_once('../../../typo3conf/localconf.php');
define('TYPO3_db_username',$typo_db_username);
define('TYPO3_db_password',$typo_db_password);
define('TYPO3_db_host',$typo_db_host);
define('TYPO3_db',$typo_db); 

$db = t3lib_div::makeInstance('t3lib_DB');
$db->connectDB(); 

$GLOBALS['TYPO3_DB'] = $db;    

Is there anyway to make this in TYPO3 6.2. I know I can wrap it in an extension or as a User Func, but I want to keep the effort low.

Thanks in advance.

include($_SERVER['DOCUMENT_ROOT'].'/typo3/sysext/core/Classes/Utility/GeneralUtility.php');
include($_SERVER['DOCUMENT_ROOT'].'/typo3/sysext/core/Classes/Database/DatabaseConnection.php');
$localConf = include $_SERVER['DOCUMENT_ROOT'].'/typo3conf/LocalConfiguration.php';

$db = new \TYPO3\CMS\Core\Database\DatabaseConnection();
$db->connectDB($localConf['DB']['host'], $localConf['DB']['username'], $localConf['DB']['password'], $localConf['DB']['database']);

$GLOBALS['TYPO3_DB'] = $db;    

So this works...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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