3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getGoals(){ $link = mysql_connect('localhost','root','root'); mysql_select_db("goal_database",$link); if (isset($_GET["pid"]) && isset($_GET["week"])) { $pid = intval($_GET["pid"]); $week = intval($_GET["week"]); $response = array(); $response["goals"] = array(); // Mysql select query to retrieve nutrition goal $nutrition_result = mysql_query("SELECT Description FROM Goals WHERE ParticipantID=$pid AND WeekNumber=$week AND Type='NUTRITION';"); $row = mysql_fetch_array($nutrition_result); $nutrition_goal = $row[0]; $tmp = array(); $tmp["nutrition"] = $nutrition_goal; array_push($response["goals"], $tmp); // Mysql query to retrieve exervise goal $exercise_result = mysql_query("SELECT Description FROM Goals WHERE ParticipantID=$pid AND WeekNumber=$week AND Type='EXERCISE';"); $row = mysql_fetch_array($exercise_result); $exercise_goal = $row[0]; $tmp["exercise"] = $exercise_goal; array_push($response["goals"], $tmp); // keeping response header to json header('Content-Type: application/json'); // echnoing json result echo json_encode($response); if (mysql_errno()) { $error = "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing:<br>\n$query\n<br>"; echo $error; } } } getGoals(); ?>
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /in/XGTMs:3 Stack trace: #0 /in/XGTMs(37): getGoals() #1 {main} thrown in /in/XGTMs on line 3
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Fatal error: Call to undefined function mysql_connect() in /in/XGTMs on line 3
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /in/XGTMs on line 3 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /in/XGTMs on line 4
Output for 4.3.0 - 4.3.1
Warning: mysql_connect() [http://www.php.net/function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /in/XGTMs on line 3 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /in/XGTMs on line 4