3v4l.org

run code in 300+ PHP versions simultaneously
<?php //include('inc/config.php'); // Define variables and initialize with empty values $username = $selected_role = $password = $confirm_password = ""; $username_err = $password_err = $confirm_password_err = ""; $host = 'localhost'; $username = 'mossgate_t'; $password = 'manchester123'; $dbname = 'mossgate_NGF'; // Create a database connection $conn = mysqli_connect($host, $username, $password, $dbname); // Check the connection if (!$conn) { die('Connection failed: ' . mysqli_connect_error()); } else { echo "error"; } try { $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $db = mysqli_connect($servername,$username,$password,$dbname); if(!$db) { die("Connection failed: " . mysqli_connect_error()); } else { echo "error"; } class DBController { private $host = "localhost"; private $user = "mossgate_t"; private $password = "manchester123"; private $database = "mossgate_NGF"; private $conn; function __construct() { $this->conn = $this->connectDB(); } function connectDB() { $conn = mysqli_connect($this->host,$this->user,$this->password,$this->database); return $conn; } function runQuery($query) { $result = mysqli_query($this->conn,$query); while($row=mysqli_fetch_assoc($result)) { $resultset[] = $row; } if(!empty($resultset)) return $resultset; } function numRows($query) { $result = mysqli_query($this->conn,$query); $rowcount = mysqli_num_rows($result); return $rowcount; } } // Processing form data when form is submitted if($_SERVER["REQUEST_METHOD"] === "POST") { $username = trim($_POST["username"]); echo "in"; echo $username; // Validate username if(empty(trim($_POST["username"]))) { echo "step1"; $username_err = "Please enter a username."; echo "Please enter a username."; } if(!preg_match('/^[a-zA-Z0-9_]+$/', trim($_POST["username"]))) { echo "3"; $username_err = "Username can only contain letters, numbers, and underscores."; echo "Username can only contain letters, numbers, and underscores."; } else { echo "in2"; // Prepare a select statement $sql = "SELECT username FROM NGF_voucher_LOGIN WHERE username = ?"; if($stmt = mysqli_prepare($db, $sql)) { echo "step2b"; // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = trim($_POST["username"]); // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)) { echo "step2c"; //store result mysqli_stmt_store_result($stmt); if(mysqli_stmt_num_rows($stmt) == 1) { echo "step2d"; $username_err = "This username is already taken."; echo "This username is already taken."; } else { echo "step2e"; $username = trim($_POST["username"]); } } else { echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } else { echo"hi"; } // Validate password if(empty(trim($_POST["password"]))){ $password_err = "Please enter a password."; } elseif(strlen(trim($_POST["password"])) < 6){ $password_err = "Password must have atleast 6 characters."; } else{ $password = trim($_POST["password"]); } // Validate confirm password if(empty(trim($_POST["confirm_password"]))){ $confirm_password_err = "Please confirm password."; } else{ $confirm_password = trim($_POST["confirm_password"]); if(empty($password_err) && ($password != $confirm_password)){ $confirm_password_err = "Password did not match."; } } // Check input errors before inserting in database if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){ // Prepare an insert statement $sql = "INSERT INTO NGF_voucher_LOGIN (username, password, role) VALUES (?,?,?)"; $selected_role = $_POST["RoleType"]; if($stmt = mysqli_prepare($db, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "sss", $param_username, $param_password,$selected_role); // Set parameters $param_username = $username; $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Redirect to login page header("location: login.php"); } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Close connection mysqli_close($conn); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Sign Up</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <style> body{ font: 14px sans-serif; } .wrapper{ width: 360px; padding: 20px; } </style> </head> <body> <div class="wrapper"> <h2>Sign Up</h2> <p>Please fill this form to create an account.</p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> <div class="form-group"> <label>Username</label> <input type="text" name="username" class="form-control <?php echo (!empty($username_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $username; ?>"> <span class="invalid-feedback"><?php echo $username_err; ?></span> </div> <br> <div class="form-group"> <label for="Role">Role type:</label> <select name="RoleType" id="RoleType"> <option value="Canteen">Canteen</option> <option value="Shiftcontroller">Shiftcontroller</option> <option value="Admin">Admin</option> </select> </div> <div class="form-group"> <label>Password</label> <input type="password" name="password" class="form-control <?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $password; ?>"> <span class="invalid-feedback"><?php echo $password_err; ?></span> </div> <div class="form-group"> <label>Confirm Password</label> <input type="password" name="confirm_password" class="form-control <?php echo (!empty($confirm_password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $confirm_password; ?>"> <span class="invalid-feedback"><?php echo $confirm_password_err; ?></span> </div> <div class="form-group"> <input type="submit" class="btn btn-primary" value="Submit"> <input type="reset" class="btn btn-secondary ml-2" value="Reset"> </div> <p>Already have an account? <a href="login.php">Login here</a>.</p> </form> </div> </body> </html>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.70.0070.01418.55
8.3.60.0300.00318.44
8.3.50.0030.01318.34
8.3.40.0200.00719.25
8.3.30.0210.01417.38
8.3.20.0280.00917.38
8.3.10.0290.00717.50
8.3.00.0330.00617.38
8.2.190.0280.00616.50
8.2.180.0320.00416.50
8.2.170.0280.01017.88
8.2.160.0250.00917.75
8.2.150.0300.01017.50
8.2.140.0310.00318.88
8.2.130.0280.00517.50
8.2.120.0330.00417.50
8.2.110.0280.01117.63
8.2.100.0360.00717.00
8.2.90.0320.00017.34
8.2.80.0240.01017.25
8.2.70.0330.00017.37
8.2.60.0280.00617.38
8.2.50.0240.00917.25
8.2.40.0260.00719.12
8.2.30.0240.00617.62
8.2.20.0230.00817.38
8.2.10.0250.00817.25
8.2.00.0270.00719.12
8.1.280.0270.00416.50
8.1.270.0350.00017.25
8.1.260.0310.00317.23
8.1.250.0330.00417.13
8.1.240.0220.00718.96
8.1.230.0190.01117.24
8.1.220.0220.00717.48
8.1.210.0210.00917.00
8.1.200.0240.00616.88
8.1.190.0180.01117.13
8.1.180.0250.00617.10
8.1.170.0280.00817.13
8.1.160.0200.01017.13
8.1.150.0280.00317.25
8.1.140.0290.00017.00
8.1.130.0190.01317.13
8.1.120.0320.00017.25
8.1.110.0340.00317.00
8.1.100.0250.01117.25
8.1.90.0340.00317.00
8.1.80.0280.00617.13
8.1.70.0250.00817.13
8.1.60.0280.00617.35
8.1.50.0270.00718.63
8.1.40.0250.00817.48
8.1.30.0310.00317.34
8.1.20.0300.00319.23
8.1.10.0310.00317.50
8.1.00.0320.00317.34

preferences:
37.47 ms | 403 KiB | 5 Q