Real-Time Updated PHP when new row inserted to MySQL?

  php, real-time, rest, restful-url

Is there a way I can get this PHP page to automatically update whenever a new row is inserted into the MySQL database? In other words, how can I make a real-time live-updating PHP page?

<?php 

include 'pdo.php';

$opid = 211;    

$query = "SELECT * from audioposts WHERE (opid = :opid)";

$values = [':opid' => $opid];

try
{
  $res = $pdo->prepare($query);
  $res->execute($values);
}
catch (PDOException $e)
{
  echo 'Query error.';
  die();
}

$row = $res->fetch(PDO::FETCH_ASSOC);

if ($row) {     
 echo $row;
}
else {
echo "empty";   
};

?>

Source: Ask PHP

LEAVE A COMMENT