来自WordPress中外部数据库的SQL查询 [英] SQL queries from an external DB in WordPress

查看:48
本文介绍了来自WordPress中外部数据库的SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我的托管网站中有一个php网站.现在,我将个性化一个Wordpress主题以替换它.暂时还可以,但是旧网站具有内置功能,可以使用令牌连接到另一个数据库.这种连接只是为了获取一些数据.

Actually I have a php website in my hosting. Now I am personalizing a Wordpress theme to replace it. It's all ok for now, but the old website has a built in function to connect to another database with a token. This connection is only to get some data.

您能告诉我如何在新的wordpress主题中实现此功能吗?
是否存在wordpress插件?

Can you tell me how to implement this in my new wordpress theme?
Did a wordpress plugin exists for this?

谢谢

推荐答案

将wordpress连接到第二个数据库(没有令牌)的最简单方法是添加这段小代码(替换字符串)通过您的连接数据):

The easiest way to connect wordpress to a second database (without a token) is to add this little piece of code (replacing strings by your connexion data) :

$wpdb2 = new WPDB( 'remote_user', 'remote_password', 'remote_db', 'remote_server');

然后,您可以使用此新对象查询所需的任何内容,就像主$ wpdb对象一样.您可以在活动的子主题(或主题)的function.php文件上使用它.

Then you can use this new object to query anything that you want to, just like the main $wpdb object. You can use this on the function.php file of your active child theme (or theme).

我认为也许有一些用于这种目的的插件……您将不得不进行搜索.

I think that maybe there is some plugins, for this kind of purpose… You will have to search.

参考:使用wpdb连接到单独的数据库

这篇关于来自WordPress中外部数据库的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆