3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); ini_set('display_errors', 'On'); ?> <?php $servername = "xxxx"; $username = "xxxx"; $password = "xxxxx"; $dbname= "xxxxx"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?> <html> <head> <title>Form</title> </head> <body> <form action="req.php" method="post"> <table> <tr> <td>Nome</td> <td><input type="text" name="nome"/></td> </tr><tr> <td>Cognome</td> <td><select name="cognome"> <?php $stmt = $conn->prepare("SELECT id, cognome FROM req_table"); $stmt->execute(); // set the resulting array to associative while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { foreach($row as $value) { echo '<option value="' . $row['id'] . '">'; echo '<option value="' . $row['cognome'] . '</option>'; } } ?> </select></td> </tr><tr> <td>Indirizzo</td> <td><select name="indirizzo"> <?php $stmt = $conn->prepare("SELECT id, indirizzo FROM req_table"); $stmt->execute(); // set the resulting array to associative while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { foreach($row as $value) { echo '<option value="' . $row['id'] . '">'; echo '<option value="' . $row['indirizzo'] . '</option>'; } } ?> </select></td> </tr><tr> <td colspan="2" style="text-align: center;"> <input type="submit" name="Invia" value="Submit" /> </td> </tr> </table> </form> </body> </html>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Connection failed: could not find driver <html> <head> <title>Form</title> </head> <body> <form action="req.php" method="post"> <table> <tr> <td>Nome</td> <td><input type="text" name="nome"/></td> </tr><tr> <td>Cognome</td> <td><select name="cognome"> Warning: Undefined variable $conn in /in/jDDQE on line 38 Fatal error: Uncaught Error: Call to a member function prepare() on null in /in/jDDQE:38 Stack trace: #0 {main} thrown in /in/jDDQE on line 38
Process exited with code 255.
Output for 7.0.5 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Connection failed: could not find driver <html> <head> <title>Form</title> </head> <body> <form action="req.php" method="post"> <table> <tr> <td>Nome</td> <td><input type="text" name="nome"/></td> </tr><tr> <td>Cognome</td> <td><select name="cognome"> Notice: Undefined variable: conn in /in/jDDQE on line 38 Fatal error: Uncaught Error: Call to a member function prepare() on null in /in/jDDQE:38 Stack trace: #0 {main} thrown in /in/jDDQE on line 38
Process exited with code 255.
Output for 7.0.0 - 7.0.4
Connection failed: could not find driver <html> <head> <title>Form</title> </head> <body> <form action="req.php" method="post"> <table> <tr> <td>Nome</td> <td><input type="text" name="nome"/></td> </tr><tr> <td>Cognome</td> <td><select name="cognome"> Notice: Undefined variable: conn in /in/jDDQE on line 38 Fatal error: Uncaught Error: Call to a member function prepare() on unknown in /in/jDDQE:38 Stack trace: #0 {main} thrown in /in/jDDQE on line 38
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Connection failed: could not find driver <html> <head> <title>Form</title> </head> <body> <form action="req.php" method="post"> <table> <tr> <td>Nome</td> <td><input type="text" name="nome"/></td> </tr><tr> <td>Cognome</td> <td><select name="cognome"> Notice: Undefined variable: conn in /in/jDDQE on line 38 Fatal error: Call to a member function prepare() on null in /in/jDDQE on line 38
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38
Connection failed: could not find driver <html> <head> <title>Form</title> </head> <body> <form action="req.php" method="post"> <table> <tr> <td>Nome</td> <td><input type="text" name="nome"/></td> </tr><tr> <td>Cognome</td> <td><select name="cognome"> Notice: Undefined variable: conn in /in/jDDQE on line 38 Fatal error: Call to a member function prepare() on a non-object in /in/jDDQE on line 38
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Class 'PDO' not found in /in/jDDQE on line 13
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/jDDQE on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected '{' in /in/jDDQE on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/jDDQE on line 12
Process exited with code 255.

preferences:
291.84 ms | 401 KiB | 458 Q