exec("PRAGMA journal_mode=WAL"); $db->exec("PRAGMA synchronous=NORMAL"); // Read the queue $ip_address = $_SERVER['REMOTE_ADDR']; //select from the sentences table where listen count is 0, then update to 1 $stmt = $db->prepare("SELECT * FROM sentences WHERE listen_count=0 ORDER BY id ASC LIMIT 1"); //$stmt = $db->prepare("SELECT * FROM sentences WHERE view_count=1 ORDER BY id ASC LIMIT 1"); //$stmt = $db->prepare("SELECT * FROM queue WHERE read=0 AND ip_address=:ip_address ORDER BY id ASC LIMIT 1"); //$stmt->bindValue(':ip_address', $ip_address); $result = $stmt->execute(); $row = $result->fetchArray(); if ($row !== false) { // Get the sentence from the database $sentence = $row['sentence']; //$sentence_id = $row['sentence_id']; //$stmt = $db->prepare("SELECT * FROM sentences WHERE id=:id"); //$stmt->bindValue(':id', $sentence_id); //$sentence_result = $stmt->execute(); //$sentence_row = $sentence_result->fetchArray(); //$sentence = $sentence_row['sentence']; // Output the sentence //error_log($sentence. "\n" . $row['id']); echo $sentence . "\n"; // Mark the sentence as read listen $stmt_update = $db->prepare("UPDATE sentences SET listen_count=1 WHERE id=:id"); $stmt_update->bindValue(':id', $row['id']); //$stmt = $db->prepare("UPDATE queue SET read=1 WHERE id=:id"); //$stmt->bindValue(':id', $row['id']); $stmt_update->execute(); } else { //queue is empty shell_exec('php php_code_initialize_db.php'); } // Close the database connection $db->close(); ?>