I have finally finished coding a project with an HTML form for file upload, and a large PHP file that submits a 200 field CSV into my database. It first uploads to a staging table and then splits the data into smaller tables. This all works perfectly but I'm having problems with the next step: This is needed to run on a wordpress site that already exists. I have a database just for this project with tables for users, clients, staging, meters, etc. I need all of these tables in their own database because these users are separate from the WP users. I found a plugin that allows you to insert PHP into pages, but I need to know how to work with a custom database in WP, I've only ever worked with the actual database. Any help is greatly appreciated.
-
Rather than inserting PHP into pages, it would be safer to create your own theme, with template PHP files which perform the necessary operations.– WebElaineMar 29, 2017 at 14:46
-
Yes, I definitely realize it can be a security issue to insert the PHP, but this was just for a testable project so I wasn't as concerned with that aspect. I was more curious about how to integrate a custom db table with the existing theme– H.NormanMar 29, 2017 at 14:50
-
1If you're inserting the PHP directly into the content it's not really a WordPress-specific question. You can just use mysqli_connect as in any PHP. If instead you'd like to do things a safer, more standard way, you'd perform the same function within theme templates - or perhaps in a plugin that you call using shortcodes.– WebElaineMar 29, 2017 at 15:34
1 Answer
Since we do not know how the data should be represented on the 'front-end' (read WP install), it is hard to say.
- You could convert the existing database to use custom tables.
- Create a small REST(1) JSON/XML(1) API(1) on the 'other' application. Then code a WordPress plugin that shows the data from the API with shortcodes. You can 'cache' this data with the use of the transients API. Or use AJAX to get the information asynchronous either via your application or some custom back-end code that uses the WordPress AJAX.
- If the data isn't that complicated, you could try to 'convert' it into a Custom Post Type. This way your data is manageable with the standard WordPress admin.
I've tried to provide some ideas how to combine WordPress and 3rd party content. This list can probably a bit longer, but these would be the obvious ones. If you could give us a bit more insight to about what data your handling, that would make it tonnes easier to assess and give you an idea to handle it.
I've also added a few links to the WordPress Codex. It contains all the necessary explanations and code examples you need.
(1) Small Google Search
(2) Third result on Google
(3) First result on Google