Home » Php » Possible to write a php script to detect a new import into a website's SQL database based on the contents of a column and trigger a PHP function?

Possible to write a php script to detect a new import into a website's SQL database based on the contents of a column and trigger a PHP function?

Posted by: admin February 25, 2020 Leave a comment


any help, solutions, ideas, or even just a push in the right direction would be greatly appreciated. I have a basic understanding of PHP, CSS, and HTML. Probably a moderate understanding of SQL and C++ due to how involved in FileMaker I have become. I just created my profile here but you can reference it for more info if you like.

So I’m not sure if or how many of these specs matter so I will try to be as complete as possible:
I am running a wordpress built website with woocommerce on an offsite Ubuntu server and working on integrating it with our on site Filemaker server where all of our product, customer, etc. data is located. I am the admin for everything and have access to all databases and interfaces.

Website Server: Dedicated 64 bit Ubuntu 18.04, Apache 2.3.29, PHP 7.2.17-0ubuntu0.18.04.1, MySQL 5.7. With only port 443 for https connections open port 80 for http is closed.

Windows Server 2019 running Filemaker Server 16 64 bit with both Filemaker Pro 16 and Filemaker Pro Advanced 18 Clients.

So what I have done is setup an ODBC connection between my FileMaker database and my website’s SQL database to upload product data at the push of a button in FileMaker. The script calculates SQL queries to insert data based on what type of product is being synced, the various options, and the contents of select fields and then returns generated ID’s for use with data insertions into other tables or later updates.

The problem that I am having is that the product data isn’t properly displayed on the website until I go into the product edit screen under wp-admin and then either hit update in the more advanced screen or it also seems to work by hitting quick-edit and then update. This creates between 30 and 40 rows of data (depending on type of product) in the wp_options table in the SQL database. I would just use scripts in FileMaker to generate all of that data as I have done for the rest of the metadata and other bits and pieces scattered throughout the other tables but the data stored in wp_options is much more complicated and seemingly indecipherable. Some of it I could probably figure out if I study it long enough and write a script to mimic the data options there while others I might be able to get by with just copying the data values, but that is going to take a long time and my FileMaker upload script will probably double in length. It already takes about 10 to 15 seconds to run the script for one product and I would like to keep that run time down and figure out a way to tell the website to generate that data when a product is uploaded.

We have over 4000 products to be uploaded with plans to add thousands more along the way as I continue to improve our site and expand it. There are also other employees that would be using Filemaker to upload products, so this needs to be as user friendly and simple for our employees as possible. Some of them are not tech savvy in the slightest… I am aware of bulk edit in wordpress but we will be constantly uploading new products in the future and so I need to make it a bit faster and more automatic than that.

I can’t send a php script or function over the ODBC connection since that only talks to the SQL server.

I have started to look into FileMakers custom web publishing API which I’m guessing would work since it works with php but I am still unfamiliar with it and have not gotten far enough into that yet to determine whether it will 100% work or not. So that will also probably end up taking a long time to get working.

So I thought of an idea. What if I wrote a php script that “watched” for new entries into the SQL database with a specific author ID under wp_posts and then called the function already established and used to update and save posts to run for the post with the ID that was just entered under the Author ID that I set aside for Filemaker? After some searching I THINK I found the function that would be used since the quick edit update seems to work and it would be this function under class-wc-admin-post-types.php

* Quick edit.
* @param int $post_id Post ID being saved.
* @param WC_Product $product Product object.

private function quick_edit_save( $post_id, $product ) {

Does anyone know if this is feasible? If it is, I would imagine a separate script would need to be created to “listen” to the SQL server and then call the function when conditions are met right?

If not, any other ideas?

How to&Answers: