php mysql update variable

Goal: Update wordpress post with PHP cli

< ?php

$con = mysql_connect("localhost","root","[redacted]");
if (!$con)
  {
 echo "Unable to connect to DB: " . mysql_error();
    exit;
  }
 if (!mysql_select_db("wordpress")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
  }
$myfileText = mysql_real_escape_string(file_get_contents('./code_for_wordpress.html',true));

$sql = "UPDATE `[your_instance_prefix]_posts` SET `post_content` = '$myfileText' WHERE `ID` like '1397';";
$result = mysql_query($sql);
 if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
  }

mysql_close($con);
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.