3v4l.org

run code in 300+ PHP versions simultaneously
<!DOCTYPE html> <?php global $db; $sqliteerror = null; try{ $db = new PDO('sqlite:/tmp/mysqlitedb.sqlite3'); } catch(Exception $e){ echo htmlentities($e->getMessage()); echo "<br><br><br>"; die('Error opening or creating new sqlite DB. Check write permissions for '.dirname(__FILE__)); } //Save if(isset($_POST['answer']) && trim($_POST['answer'])){ $sql = 'INSERT INTO survey (answer) VALUES (\''.$_POST['answer'].'\')'; $db->query($sql); } ?> <html> <head> <title></title> </head> <body> <fieldset> <legend>SURVEY: What is the best food?</legend> <form method="POST"> <label>Answer: <input type="text" name="answer"></label> <input type="submit"> </form> </fieldset> <fieldset> <legend>SURVEY: Previous Answers</legend> <?php $sql = 'SELECT COUNT(*) as x, `answer` FROM survey WHERE `answer` != \'\' GROUP BY `answer`'; foreach ($db->query($sql) as $row) { echo $row['x'] . "x ".$row['answer'].'<br>'; } ?> </fieldset> </body> </html>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <fieldset> <legend>SURVEY: What is the best food?</legend> <form method="POST"> <label>Answer: <input type="text" name="answer"></label> <input type="submit"> </form> </fieldset> <fieldset> <legend>SURVEY: Previous Answers</legend> Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1 no such table: survey in /in/6Gim1:38 Stack trace: #0 /in/6Gim1(38): PDO->query('SELECT COUNT(*)...') #1 {main} thrown in /in/6Gim1 on line 38
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <fieldset> <legend>SURVEY: What is the best food?</legend> <form method="POST"> <label>Answer: <input type="text" name="answer"></label> <input type="submit"> </form> </fieldset> <fieldset> <legend>SURVEY: Previous Answers</legend> Warning: Invalid argument supplied for foreach() in /in/6Gim1 on line 38 </fieldset> </body> </html>

preferences:
198.01 ms | 403 KiB | 225 Q