3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); ini_set('display_errors', 1); //$a = print_r(var_dump($GLOBALS),1); //echo htmlspecialchars($a); $servername = "#"; $username = "#"; $password = "#"; $dbname = "#"; // Create connection //$conn = mysqli_connect($servername, $username, $password, $dbname); //echo "Connection Successful : "; // Check connection //if (!$conn) { // die("Connection failed: " . mysqli_connect_error()); //} // Read JSON file //$jsondata = file_get_contents('scripts/AUDIT_DIR/report.json'); //echo "JSON File Read : "; // Convert and Loop //$item = json_decode($jsondata, true); $item = null; echo "JSON File Decoded : "; foreach($item as $arr) { $id = $arr["id"]; $hostname = $arr["hostname"]; $ip = $arr["ip"]; $package = $arr["package"]; $publisher = $arr["publisher"]; $origin = $arr["origin"]; $version = $arr["version"]; $size = $arr["size"]; //$sql = "INSERT INTO testtable(id, hostname, ip, package, publisher, origin, version, size) //VALUES ('10', '$hostname', '$ip', '$package', '$publisher', '$origin', '$version', '$size')"; if (mysqli_query($conn, $sql)) { echo "New record created successfully : "; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
JSON File Decoded : Warning: foreach() argument must be of type array|object, null given in /in/oNr8P on line 31
Output for 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
JSON File Decoded : Warning: Invalid argument supplied for foreach() in /in/oNr8P on line 31

preferences:
152.77 ms | 408 KiB | 5 Q