简体   繁体   English

使用多个数据库的Symfony查询

[英]Symfony query with multiple databases

This site has been great for a Symfony newbie such as myself and hopefully this will be the same experience. 该站点对于像我这样的Symfony新手来说非常有用,希望这将是相同的体验。 I have searched a lot for this question so maybe I am not using the right terminology. 我已经搜索了很多这个问题,所以也许我没有使用正确的术语。 I have read about using services but none seem to give an example of what I need using multiple databases with different tables. 我已经阅读了有关使用服务的信息,但似乎都没有给出使用多个具有不同表的数据库所需要的示例。 So here goes, first off I am at the discretion of the current database design and I can't merge databases or recreate them, I have to use them as is. 因此,首先,我是当前数据库设计的决定者,我无法合并或重新创建数据库,必须按原样使用它们。 Here is the mysql query I want to use: 这是我要使用的mysql查询:

select name, title, rank from db1.tbl1, 
db2.tbl1,db2.tbl2 
where db2.tbl1.id=db2.tbl.id
and db1.tbl1.person_id=db2.tbl2.person_id;

I have created connections to the db in parameters.yml and config.yml. 我已经在parameters.yml和config.yml中创建了到数据库的连接。 I was thinking about creating a repository for one of the entities and then having it innerjoin the other tables from the same database but couldn't find any examples. 我当时正在考虑为其中一个实体创建一个存储库,然后让它内部连接同一数据库中的其他表,但是找不到任何示例。 I want to do this using best practice. 我想使用最佳实践来做到这一点。 I am all ears. 洗耳恭听。

I should also mention all the databases are managed by the same server. 我还要提到所有数据库都由同一服务器管理。

You can't use multiple databases in a single query because for multiple databases to work, you need a manager for each . 您不能在单个查询中使用多个数据库,因为要使用多个数据库,每个数据库都需要一个管理器

I can't think of a solution using arrays or objects that is not resource intensive. 我想不出使用不占用大量资源的数组或对象的解决方案。 Because you need to load at least one entire table. 因为您需要加载至少一个整个表。

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

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