I need some help here.
Some background info: I'm using a mysql database.
In this example I'll call the database test9000
My goal is to be able to check the following columns in the db:
post_modified && ID against a backup the same db.
Here will be the sql query to retrieve info:
SELECT wp_posts.post_modified, wp_post***** FROM test9000.wp_posts.
The ultimate goal is once a check it done, to see which db has the latest posts_modified, and replace the old post with a new.
For instance, I write page A, you write page B and then we sync. If we try to jam the two backups together our ids will clash.
This has to be done in PHP. I'm just stumped at how to open up my db back up file and select only the relevant table and then compare.
Here is my code so far:
Code:
<?php
if (!file_exists(CREATE_SCRIPT)) {
$error = 'Cannot find file "' . CREATE_SCRIPT . '".';
} else {
$sql = file_get_contents(CREATE_SCRIPT);
if(!$sql)
$error = 'Unable to read file "' . CREATE_SCRIPT . '".';
}
if (!$error) {
$con = mysql_connect(SQL_HOST,ADMIN_USER,ADMIN_PASSWORD);
if (!$con)
$error = 'Could not connect: ' . mysql_error();
}
$old_post = mysql_query("SELECT wp_posts.post_modified, wp_post***** FROM test9000.wp_posts", $con);
// Go into the db dump file and select the contents for the table "wp_posts" only
$new_post = null;
// Compare the contents of the columns "posts_modified and ID" to $old_post
if() {
// if the old stuff is newer, do nothing
}
else {
// if the contents of the dump is newer, drop the old content for $old_post
// and replace it with the content from $new_post
}
?>
Any help would be greatly appreciated. If this isn't the right place to post, just let me know.