CodeIgniter为读取和写入MySQL数据配置不同的IP

发布于 2024-09-17 17:05:27 字数 115 浏览 14 评论 0原文

我的公司一直在设置不同的服务器来读取和写入 mysql DB。以前,我们使用自定义 php 脚本。 然而,我最近接到的任务是利用 CI 创建工具。我已经在测试服务器上完成了。现在,我很困惑,如何在实时服务器上实现它。

My company has been setting up a different server for read and write access of mysql DB. Previously, we use custom php script.
However, I was recently given task to create tools by leveraging CI. I've done it on test server. Now, I'm confused, how to implement it on live server.

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

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

发布评论

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

评论(2

池木 2024-09-24 17:05:27

在database.php配置文件中为每个服务器设置多个“连接组”,然后在模型中:

$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);

//read from DB1
$DB1->query();

//write to DB2
$DB2->insert();

请参阅以下示例: 连接到多个数据库

Setup multiple 'connection groups' for each server in your database.php config file, then in the Model:

$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);

//read from DB1
$DB1->query();

//write to DB2
$DB2->insert();

See examples in: Connecting to Multiple Databases

浪菊怪哟 2024-09-24 17:05:27

与通过 IP 执行此操作相比,使用 MySQL 用户执行此操作可能会更容易。

您可以有两个不同的用户,一个具有所有写入权限,例如 INSERTUPDATE,然后另一个用户具有所有读取权限,例如 SELECT,或者你想要什么。

那么,在您的写入 Web 服务器上运行的代码使用写入用户,反之亦然?

Might it be easier, rather than doing this by IP, do it using MySQL users.

You could have two different users, one with all the write privileges like INSERT and UPDATE, then another user with all the READ privileges like SELECT, or what ever you wish.

Then what ever code is running on your write web server uses the write user and vice-a-versa?

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