Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
339 views
Welcome To Ask or Share your Answers For Others

1 Answer

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');

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.

Reference: Using wpdb to connect to a separate database


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...