3v4l.org

run code in 300+ PHP versions simultaneously
<?php $link = mysql_connect('localhost', 'root', 'root'); if (!$link) { die('Could not connect: ' . mysql_error()); } else { echo 'Connected successfully' . "<br>"; } $db_selected = mysql_select_db('Test_DB', $link); if (!$db_selected) { die ('Can\'t use Test_DB : ' . mysql_error()); } else { echo 'Test_DB selected' . "<br>"; } // This SQL statement selects ALL from the table 'Contacts' $sql = "SELECT * FROM Contacts"; $result = mysql_query($sql); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $sql; die($message); } else { echo 'Result: ' . $result; $resultArray = array(); $tempArray = array(); // Loop through each row in the result set while ($row = mysql_fetch_array($result)) { // do stuff - here it works $tempArray = $row; array_push($resultArray, $tempArray); } // Finally, encode the array to JSON and output the results echo json_encode($resultArray); } // Check if there are results // if ($result = mysql_query($link, $sql)) if ($result = mysql_query($sql, $link)) { // If so, then create a results array and a temporary one // to hold the data $resultArray = array(); $tempArray = array(); // Loop through each row in the result set while($row = $result->fetch_object()) { // Add each row into our results array $tempArray = $row; array_push($resultArray, $tempArray); } // Finally, encode the array to JSON and output the results echo json_encode($resultArray); } // Close connections mysql_close($link); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 43
Branch analysis from position: 34
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 48
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 84
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 71
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 71
Branch analysis from position: 80
Branch analysis from position: 71
Branch analysis from position: 84
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 48
Branch analysis from position: 58
Branch analysis from position: 48
filename:       /in/EL3Rs
function name:  (null)
number of ops:  88
compiled vars:  !0 = $link, !1 = $db_selected, !2 = $sql, !3 = $result, !4 = $message, !5 = $resultArray, !6 = $tempArray, !7 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'mysql_connect'
          1        SEND_VAL_EX                                              'localhost'
          2        SEND_VAL_EX                                              'root'
          3        SEND_VAL_EX                                              'root'
          4        DO_FCALL                                      0  $8      
          5        ASSIGN                                                   !0, $8
    5     6        BOOL_NOT                                         ~10     !0
          7      > JMPZ                                                     ~10, ->13
    6     8    >   INIT_FCALL_BY_NAME                                       'mysql_error'
          9        DO_FCALL                                      0  $11     
         10        CONCAT                                           ~12     'Could+not+connect%3A+', $11
         11      > EXIT                                                     ~12
         12*       JMP                                                      ->14
    8    13    >   ECHO                                                     'Connected+successfully%3Cbr%3E'
   11    14        INIT_FCALL_BY_NAME                                       'mysql_select_db'
         15        SEND_VAL_EX                                              'Test_DB'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $13     
         18        ASSIGN                                                   !1, $13
   12    19        BOOL_NOT                                         ~15     !1
         20      > JMPZ                                                     ~15, ->26
   13    21    >   INIT_FCALL_BY_NAME                                       'mysql_error'
         22        DO_FCALL                                      0  $16     
         23        CONCAT                                           ~17     'Can%27t+use+Test_DB+%3A+', $16
         24      > EXIT                                                     ~17
         25*       JMP                                                      ->27
   15    26    >   ECHO                                                     'Test_DB+selected%3Cbr%3E'
   19    27        ASSIGN                                                   !2, 'SELECT+%2A+FROM+Contacts'
   22    28        INIT_FCALL_BY_NAME                                       'mysql_query'
         29        SEND_VAR_EX                                              !2
         30        DO_FCALL                                      0  $19     
         31        ASSIGN                                                   !3, $19
   23    32        BOOL_NOT                                         ~21     !3
         33      > JMPZ                                                     ~21, ->43
   24    34    >   INIT_FCALL_BY_NAME                                       'mysql_error'
         35        DO_FCALL                                      0  $22     
         36        CONCAT                                           ~23     'Invalid+query%3A+', $22
         37        CONCAT                                           ~24     ~23, '%0A'
         38        ASSIGN                                                   !4, ~24
   25    39        CONCAT                                           ~26     'Whole+query%3A+', !2
         40        ASSIGN_OP                                     8          !4, ~26
   26    41      > EXIT                                                     !4
         42*       JMP                                                      ->62
   28    43    >   CONCAT                                           ~28     'Result%3A+', !3
         44        ECHO                                                     ~28
   30    45        ASSIGN                                                   !5, <array>
   31    46        ASSIGN                                                   !6, <array>
   34    47      > JMP                                                      ->53
   37    48    >   ASSIGN                                                   !6, !7
   38    49        INIT_FCALL                                               'array_push'
         50        SEND_REF                                                 !5
         51        SEND_VAR                                                 !6
         52        DO_ICALL                                                 
   34    53    >   INIT_FCALL_BY_NAME                                       'mysql_fetch_array'
         54        SEND_VAR_EX                                              !3
         55        DO_FCALL                                      0  $33     
         56        ASSIGN                                           ~34     !7, $33
         57      > JMPNZ                                                    ~34, ->48
   42    58    >   INIT_FCALL                                               'json_encode'
         59        SEND_VAR                                                 !5
         60        DO_ICALL                                         $35     
         61        ECHO                                                     $35
   48    62        INIT_FCALL_BY_NAME                                       'mysql_query'
         63        SEND_VAR_EX                                              !2
         64        SEND_VAR_EX                                              !0
         65        DO_FCALL                                      0  $36     
         66        ASSIGN                                           ~37     !3, $36
         67      > JMPZ                                                     ~37, ->84
   52    68    >   ASSIGN                                                   !5, <array>
   53    69        ASSIGN                                                   !6, <array>
   56    70      > JMP                                                      ->76
   59    71    >   ASSIGN                                                   !6, !7
   60    72        INIT_FCALL                                               'array_push'
         73        SEND_REF                                                 !5
         74        SEND_VAR                                                 !6
         75        DO_ICALL                                                 
   56    76    >   INIT_METHOD_CALL                                         !3, 'fetch_object'
         77        DO_FCALL                                      0  $42     
         78        ASSIGN                                           ~43     !7, $42
         79      > JMPNZ                                                    ~43, ->71
   64    80    >   INIT_FCALL                                               'json_encode'
         81        SEND_VAR                                                 !5
         82        DO_ICALL                                         $44     
         83        ECHO                                                     $44
   69    84    >   INIT_FCALL_BY_NAME                                       'mysql_close'
         85        SEND_VAR_EX                                              !0
         86        DO_FCALL                                      0          
   71    87      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.38 ms | 1404 KiB | 17 Q