我正在编写一个typo3插件,需要在可配置的MySQL/MariaDB数据库服务器上访问预定义结构的数据库表。这是我写的模型:
<?php
namespace HomeinfoSysMon2DomainModel;
use TYPO3CMSExtbaseDomainObjectAbstractEntity;
class CheckResults extends AbstractEntity
{
/**
* @var int $id
*/
public $id;
/**
* @var DateTime $timestamp
*/
public $timestamp;
/**
* @var int $system
*/
public $system;
/**
* @var bool $icmp_request
*/
public $icmp_request;
/**
* @var string $ssh_login
*/
public $ssh_login ;
/**
* @var string $http_request
*/
public $http_request;
/**
* @var string $application_state
*/
public $application_state;
/**
* @var string $smart_check
*/
public $smart_check;
/**
* @var string $baytrail_freeze
*/
public $baytrail_freeze;
/**
* @var string $fsck_repair
*/
public $fsck_repair;
/**
* @var bool $application_version
*/
public $application_version;
/**
* @var int $ram_total
*/
public $ram_total;
/**
* @var int $ram_free
*/
public $ram_free;
/**
* @var int $ram_available
*/
public $ram_available;
/**
* @var string $efi_mount_ok
*/
public $efi_mount_ok;
/**
* @var int $download
*/
public $download;
/**
* @var int $upload
*/
public $upload;
/**
* @var string $root_not_ro
*/
public $root_not_ro;
/**
* @var string $sensors
*/
public $sensors;
/**
* @var bool $in_sync
*/
public $in_sync;
/**
* @var int $recent_touch_events
*/
public $recent_touch_events;
/**
* @var DateTime $offline_since
*/
public $offline_since;
/**
* @var DateTime $blackscreen_since
*/
public $blackscreen_since;
}
当然,这不能正常工作,因为Typo3假定模型表示本地Typo3数据库中ext_tables.{php,sql}
定义的表。但我希望typo3使用来自另一个可配置数据库服务器的模型,由
- 主机名/gh>
- 口 <
- 用户名/gh>
我该怎么做呢?我想使用尽可能多的高级抽象,不想使用mysqli
或类似的工具编写简单的SQL查询。
您可以将多个数据库附加到TYPO3并建立一个映射,这个特殊的新数据库应该用于哪些表,请参阅https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/Configuration/Typo3ConfVars/DB.html#tablemapping了解您的特定版本,但这里提到的示例
'Connections' => [
'Default' => [
// ...
],
'Syslog' => [
'charset' => 'utf8mb4',
'driver' => 'mysqli',
'dbname' => 'syslog_dbname',
'host' => 'syslog_host',
'password' => '***',
'port' => 3306,
'user' => 'syslog_user',
],
],
'TableMapping' => [
'sys_log' => 'Syslog',
]
应该给你一个很好的一瞥。根据您的用例,
可能会有所帮助- 对数据库具有只读的SQL访问权限,以便破坏性的数据库比较不会使外部系统无效。
- 或者有一些额外的typo3友好的字段(例如uid, pid)在其中,帮助实现你想要的。