Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress site - using custom PHP and database

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.

like image 306
H.Norman Avatar asked Aug 06 '26 14:08

H.Norman


2 Answers

Include wordpress db file in your script 'wp-admin/includes/upgrade.php' and then call

global $wpdb;
$wpdb->query($your_query_string);

This way you can use wordpress database. But go through wordpress once so you will be aware of tables. Because wordpress save specific data to specific tables, say - any informartion about user to user_meta table.

If you are trying to insert new users then you may need to enter data into user table.

Another method is there.

You can open your wordpress theme's function.php then you can write scripts to enter your data or what ever fuctionality you are looking for. And I think that is a better way to work with wordpress.

like image 56
Alice Avatar answered Aug 09 '26 04:08

Alice


If you want to use php, try this tutorial: https://www.w3schools.com/php/php_ref_mysqli.asp

If you are developing wordpress plugins check out the wordpress codex: https://codex.wordpress.org/Creating_Tables_with_Plugins

This is going to take a bit of research on your part. Good luck!

like image 21
n8bar Avatar answered Aug 09 '26 04:08

n8bar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!