[英]ORM model for foreign database in typo3
I am writing a typo3 plugin that needs to access a database table of a pre-defined structure on a configurable MySQL / MariaDB database server.我正在编写一个 typo3 插件,它需要访问可配置 MySQL / MariaDB 数据库服务器上预定义结构的数据库表。 This is the model I wrote:
这是我写的model:
<?php
namespace Homeinfo\SysMon2\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
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;
}
Of course this does not work as it stands, since Typo3 assumes the model to represent a table as defined by ext_tables.{php,sql}
within the local typo3 database.当然,这并不像现在这样工作,因为 Typo3 假定 model 表示本地typo3 数据库中由
ext_tables.{php,sql}
定义的表。 But I want typo3 to use this model from another, configurable database server, identified by但我希望 typo3 从另一个可配置的数据库服务器使用这个 model,由
How would I go about that?我怎么会go呢? I want to use as much high-level abstraction as possible and do not want to write bare SQL queries using
mysqli
or the like.我想尽可能多地使用高级抽象,不想使用
mysqli
等编写裸 SQL 查询。
You can have multiple databases attached to TYPO3 and establish a mapping for which tables this special new database should be used, refer to https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/Configuration/Typo3ConfVars/DB.html#tablemapping for your specific version but the example mentioned there您可以将多个数据库附加到 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',
]
should give you a good glimpse.应该给你一个很好的一瞥。 Depending on your use case it could be helpful to
根据您的用例,它可能有助于
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.