简体   繁体   English

TYPO3 6.2 PHP脚本数据库连接

[英]TYPO3 6.2 PHP script database connection

I should do an Upgrade to TYPO3 6.2. 我应该升级到TYPO3 6.2。 In some old extension there are several php scripts which are directly called by an URL. 在某些旧扩展中,有几个直接由URL调用的php脚本。 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. 无论如何,在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... 所以这可行...

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

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