Is it possible to query from external database?

admin2025-06-04  2

This question already has answers here: Using wpdb to connect to a separate database (6 answers) Closed 6 years ago.

I have an extarnal database that I want to show some data in my wordpress site. What are the necessary steps to achieve this?

edit: I changed config.inc.php according to but it enabled me to see the hostName of the external server visible by phpmyadmin. With the wordpress root I can enter the external database.

Up to here is good. But I do not have any clue about how to advance. I searched plugin to show the new database but I could not find any. I am new to the wordpress, so pardon me for my beginner questions. I want to show the data in different pages, with the unique string name that is the same as in the external database, ie: page name is the specifier query name.

This question already has answers here: Using wpdb to connect to a separate database (6 answers) Closed 6 years ago.

I have an extarnal database that I want to show some data in my wordpress site. What are the necessary steps to achieve this?

edit: I changed config.inc.php according to https://stackoverflow/questions/16801573/how-to-access-remote-server-with-local-phpmyadmin-client but it enabled me to see the hostName of the external server visible by phpmyadmin. With the wordpress root I can enter the external database.

Up to here is good. But I do not have any clue about how to advance. I searched plugin to show the new database but I could not find any. I am new to the wordpress, so pardon me for my beginner questions. I want to show the data in different pages, with the unique string name that is the same as in the external database, ie: page name is the specifier query name.

Share Improve this question edited Jan 24, 2019 at 22:02 elections 12 asked Jan 24, 2019 at 21:25 elections 12elections 12 1011 silver badge2 bronze badges 1
  • Can you provide some more details on what you're trying to achieve? WordPress is built on PHP so you can use regular PHP to access any database you want. – mrben522 Commented Jan 24, 2019 at 21:31
Add a comment  | 

1 Answer 1

Reset to default 2

You can use wpdb to setup a new connection.

Add something similar to this below in your functions.php and you can then query just like you would normally but using the new connection.

$second_db = new wpdb(DB_USER, DB_PASSWORD, $database_name, DB_HOST);
$results = $second_db->get_results($your_query);

references:

https://wordpress.stackexchange/a/1673/86845

https://stackoverflow/a/36759606/3204142

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748976516a315316.html

最新回复(0)