$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Is it possible to query from external database?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Is it possible to query from external database?

matteradmin9PV0评论
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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far