推动 ORM 并发连接

发布于 2024-12-27 16:39:56 字数 212 浏览 0 评论 0原文

我正在使用 Propel ORM 开发一个项目,需要连接到两个不同的数据库来检索某些数据。我尝试在网上搜索指南,但没有运气,因为所有“解决方案”要么特定于 Symphony,要么根本不起作用。

我希望能够指定两个连接,并能够通过向查询传递连接别名来在某些查询期间在它们之间进行切换。但是,同时打开两个连接也是可以接受的。

非常感谢任何和所有的帮助!

谢谢, 迪马

I am working on a project using Propel ORM and need to connect to two different databases to retrieve certain data. I've attempted searching online for a guide, but had no luck as all the "solutions" were either specific to Symphony or just simply did not work.

I would like to be able to have two connections specified and be able to switch between them during certain queries by passing a connection alias to the query. However, it is also acceptable to have both connections open simultaneously.

Any and all help is greatly appreciated!

Thanks,
Dima

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2025-01-03 16:39:56

根据 Propel API 文档,您可以在架构中定义数据库连接.xml 文件以这种方式:

<?xml version="1.0" encoding="UTF-8"?>
<database name="bookstore" defaultIdMethod="native">
    <!-- table definitions go here -->
</database>

然后在您的 runtime-conf.xml 设置,您可以设置连接参数:

<datasources default="bookstore">
  <datasource id="bookstore">
    <adapter>mysql</adapter> <!-- sqlite, mysql, mssql, oracle, or pgsql -->
    <connection>
      <dsn>mysql:host=localhost;dbname=my_db_name</dsn>
      <user>my_db_user</user>
      <password>my_db_password</password>
    </connection>
  </datasource>
</datasources>

-- 编辑 --

似乎 Propel 不支持数据库标签的别名属性,但您应该能够获得放弃以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<database name="bookstore_primary" defaultIdMethod="native">
    <!-- table definitions go here -->
</database>

<database name="bookstore_secondary" defaultIdMethod="native">
    <!-- table definitions go here -->
</database>

<datasources default="bookstore_primary">
  <datasource id="bookstore_primary">
    <adapter>mysql</adapter> <!-- sqlite, mysql, mssql, oracle, or pgsql -->
    <connection>
      <dsn>mysql:host=localhost;dbname=bookstore_primary</dsn>
      <user>my_db_user</user>
      <password>my_db_password</password>
    </connection>
  </datasource>
</datasources>

<datasources default="bookstore_secondary">
  <datasource id="bookstore_secondary">
    <adapter>mysql</adapter> <!-- sqlite, mysql, mssql, oracle, or pgsql -->
    <connection>
      <dsn>mysql:host=localhost;dbname=bookstore_secondary</dsn>
      <user>my_db_user</user>
      <password>my_db_password</password>
    </connection>
  </datasource>
</datasources>

看看是否有效。归根结底,真正重要的是可以与两个数据库建立连接(使用各自的 DSN)。

According to the Propel API Docs you can define a database connection in your schema.xml file in such a manner:

<?xml version="1.0" encoding="UTF-8"?>
<database name="bookstore" defaultIdMethod="native">
    <!-- table definitions go here -->
</database>

Then in your runtime-conf.xml settings you can set the connection params:

<datasources default="bookstore">
  <datasource id="bookstore">
    <adapter>mysql</adapter> <!-- sqlite, mysql, mssql, oracle, or pgsql -->
    <connection>
      <dsn>mysql:host=localhost;dbname=my_db_name</dsn>
      <user>my_db_user</user>
      <password>my_db_password</password>
    </connection>
  </datasource>
</datasources>

-- Edit --

Doesn't appear that Propel supports an alias attribute for the database tag, but you should be able to get away with the following:

<?xml version="1.0" encoding="UTF-8"?>
<database name="bookstore_primary" defaultIdMethod="native">
    <!-- table definitions go here -->
</database>

<database name="bookstore_secondary" defaultIdMethod="native">
    <!-- table definitions go here -->
</database>

<datasources default="bookstore_primary">
  <datasource id="bookstore_primary">
    <adapter>mysql</adapter> <!-- sqlite, mysql, mssql, oracle, or pgsql -->
    <connection>
      <dsn>mysql:host=localhost;dbname=bookstore_primary</dsn>
      <user>my_db_user</user>
      <password>my_db_password</password>
    </connection>
  </datasource>
</datasources>

<datasources default="bookstore_secondary">
  <datasource id="bookstore_secondary">
    <adapter>mysql</adapter> <!-- sqlite, mysql, mssql, oracle, or pgsql -->
    <connection>
      <dsn>mysql:host=localhost;dbname=bookstore_secondary</dsn>
      <user>my_db_user</user>
      <password>my_db_password</password>
    </connection>
  </datasource>
</datasources>

See if that works. At the end of the day the thing that really matters is that a connection can be made to both databases (using respective DSNs).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文