• Hey guys, pretty new to WordPress and PHP development and I’m having some difficulty with this task.

    Basically my client has a mysql database(it’s on the same server as wordpress db) and a php file that works with a few other files (one that actually connects to the database) and outputs some data and html formatting. I’ve been trying to integrate this into a wordpress page but the include command doesn’t seem to work. This is probably because it’s trying to connect to a second database, because when I include a php file with just an echo, it displays fine.

    I’ve read that you can use something called a wpdb class but I don’t know where it should go or how it’s used it in this situation. If anyone could maybe direct me into the right direction, I would really appreciate it.

    The way the php file works is that it includes these two other files, a func.php and a config.php file, config has the mysql credentials and func file makes the actual connection. It works just fine when I open it by itself, but when I include it on a wordpress page using <?php include(“file.php”) ;?>, nothing comes up. Thank you for all the help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • My suggestion is that you consolidate the two databases into one.
    On the ‘other’ database, do an export, then in the WordPress database import this file, now you will have one database with both the wordpress tables AND also the other tables, this will be fine just so long as you don’t have a table name in common (which is unlikely).

    Now you can access all your data using the $wpdb database connection. Do this by creating a custom page template which borrows your client’s code, it can do all the database entry / edit / add etc operations just like how the client stand alone pages did, all under the WordPress umbrella.

    Once you get some perspective on this organisation, checkout how you can use shortcodes to help, details here:
    http://codex.wordpress.org/Shortcode_API

    Thread Starter heyihsan

    (@heyihsan)

    Ross, thank you very much for your suggestion. However, the client had his setup for a long time now and he accesses this through MS Access, and honestly I don’t want to mess up with this setup. Is there any way to get this done without having to consolidate two databases?

    So it seems that using $wpdb is out of the question, as is creating a second $wpdb object to handle MS-access.
    Still you have php files which do handle MS-access, I see no reason why this code cannot operate within the WordPress framework.

    I understand that you have tried to use file include, but to no result. I think that this approach is worth pursuing. Enable DEBUG messages (temporarily) in your WordPress by editing your wp-config.php so that the WP_DEBUG setting is true: “define(‘WP_DEBUG’, true);”
    It would be best if your function DID NOT echo anything, but rather returned its text to be displayed as text strings, this will give you greater flexibility in how the display happens and where. Using shortcodes is likely to be useful, details here:
    http://codex.wordpress.org/Shortcode_API

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Include a php file that connects to another database to a page’ is closed to new replies.