3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildQuery($retrievables, $table, $limit = 0, $conditions = "", $orderCondition = "", $orderDirection = "") { $query = "SELECT $retrievables FROM $table"; // if we have conditions - add them to the query $query .= ($conditions != "" ? " WHERE " . $conditions : ""); // if we have a limit - add it to the query $query .= ($limit != 0 ? " LIMIT " . $limit : ""); // if we have to order the results - add it to the query $query .= ($orderCondition != "" ? " ORDER BY " . $orderCondition . " " . $orderDirection : ""); // first we create a "dictionary" which translates $niceValues that are used throughout the code // to $realValues which are used in the MySQL database // since the $realValues are different in every table - we must account to that switch ($table) { case 'usersTable': $niceValues = array("userID", "userName", "userAge", "userLocation", "userSex", "userIntention", "usersTable"); $realValues = array("uid", "uname", "user_bdate", "user_from", "name", "user_intrest", "nuke_users"); // yeah - the field "name" is really the sex of the user break; case 'articlesTable': $niceValues = array("articleID", "articleTitle", "articleLead", "articleBody", "articlesTable"); $realValues = array("sid", "title", "hometext", "bodytext", "nuke_stories"); break; default: $realValues = array(); } // we then replace $niceValues with $realValues $modifiedQuery = str_ireplace($niceValues, $realValues, $query); return $modifiedQuery; } print_r(buildQuery($retrievables, "usersTable", "", "uid=$userID")); ?>
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
Warning: Undefined variable $retrievables in /in/HTZkl on line 31 Warning: Undefined variable $userID in /in/HTZkl on line 31 SELECT FROM nuke_users WHERE uid= LIMIT
Output for 5.0.4 - 5.0.5, 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.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: retrievables in /in/HTZkl on line 31 Notice: Undefined variable: userID in /in/HTZkl on line 31 SELECT FROM nuke_users WHERE uid=
Output for 7.3.32 - 7.3.33
SELECT FROM nuke_users WHERE uid=
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: retrievables in /in/HTZkl on line 31 Notice: Undefined variable: userID in /in/HTZkl on line 31 SELECT FROM nuke_users WHERE uid=
Output for 4.4.5 - 4.4.9
Notice: Undefined variable: retrievables in /in/HTZkl on line 31 Notice: Undefined variable: userID in /in/HTZkl on line 31 Fatal error: Call to undefined function: str_ireplace() in /in/HTZkl on line 27
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Notice: Undefined variable: retrievables in /in/HTZkl on line 31 Notice: Undefined variable: userID in /in/HTZkl on line 31 Fatal error: Call to undefined function: str_ireplace() in /in/HTZkl on line 27
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Undefined variable: retrievables in /in/HTZkl on line 31 Notice: Undefined variable: userID in /in/HTZkl on line 31 Fatal error: Call to undefined function: str_ireplace() in /in/HTZkl on line 27

preferences:
206.54 ms | 402 KiB | 349 Q