3v4l.org

run code in 500+ PHP versions simultaneously
<?php function prepared_mysqli_query($query) { //initializing required variables $first_half = ''; $placeholders = ''; $data_types = ''; $values = ''; //getting the first half of query $trim_end = strrpos($query,'('); $first_half = substr($query, 0, $trim_end); //getting the values to be inserted $open = strrpos($query,'('); $close = strrpos($query,')'); $values = substr($query,($open+1),($close+1)); $values_stripped = substr($values,0,-1); $values_array = explode(",",$values_stripped); $values_count = count($values_array); //generating placeholders $ph = "("; for ($i = 1; $i < $values_count; $i++) { $ph.= "?,"; } $ph.= "?)"; $placeholders .= $ph; //getting value types $types =''; for ($i = 0; $i < $values_count; $i++){ $str = gettype($values_array[0]); $types .= $str[0]; } $data_types .= $types; //execution $query = $first_half.$placeholders; return ["query" => $query, "data_types" => $data_types, "values" => $values_array ]; } var_dump(prepared_mysqli_query("INSERT INTO `tablename` (`column1`, `column2`, `column3`) VALUES (NULL, 'v1', 'v2');")); var_dump(prepared_mysqli_query("INSERT INTO `tablename` (`column1`, `column2`, `column3`) VALUES (NOW(), 'v1', 'v2');")); var_dump(prepared_mysqli_query("INSERT INTO `tablename` (`column1`, `column2`, `column3`) VALUES ('test,with,commas', 'v1', 'v2');")); var_dump(prepared_mysqli_query("INSERT INTO `tablename` (`column1`, `column2`, `column3`) VALUES ('v0', 'v1', 'v2') ON DUPLICATE KEY UPDATE `column2` = 'v2';"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/puKfE
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   49     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'prepared_mysqli_query'
          2        SEND_VAL                                                     'INSERT+INTO+%60tablename%60+%28%60column1%60%2C+%60column2%60%2C+%60column3%60%29+VALUES+%28NULL%2C+%27v1%27%2C+%27v2%27%29%3B'
          3        DO_FCALL                                          0  $0      
          4        SEND_VAR                                                     $0
          5        DO_ICALL                                                     
   51     6        INIT_FCALL                                                   'var_dump'
          7        INIT_FCALL                                                   'prepared_mysqli_query'
          8        SEND_VAL                                                     'INSERT+INTO+%60tablename%60+%28%60column1%60%2C+%60column2%60%2C+%60column3%60%29+VALUES+%28NOW%28%29%2C+%27v1%27%2C+%27v2%27%29%3B'
          9        DO_FCALL                                          0  $2      
         10        SEND_VAR                                                     $2
         11        DO_ICALL                                                     
   53    12        INIT_FCALL                                                   'var_dump'
         13        INIT_FCALL                                                   'prepared_mysqli_query'
         14        SEND_VAL                                                     'INSERT+INTO+%60tablename%60+%28%60column1%60%2C+%60column2%60%2C+%60column3%60%29+VALUES+%28%27test%2Cwith%2Ccommas%27%2C+%27v1%27%2C+%27v2%27%29%3B'
         15        DO_FCALL                                          0  $4      
         16        SEND_VAR                                                     $4
         17        DO_ICALL                                                     
   55    18        INIT_FCALL                                                   'var_dump'
         19        INIT_FCALL                                                   'prepared_mysqli_query'
         20        SEND_VAL                                                     'INSERT+INTO+%60tablename%60+%28%60column1%60%2C+%60column2%60%2C+%60column3%60%29+VALUES+%28%27v0%27%2C+%27v1%27%2C+%27v2%27%29+ON+DUPLICATE+KEY+UPDATE+%60column2%60+%3D+%27v2%27%3B'
         21        DO_FCALL                                          0  $6      
         22        SEND_VAR                                                     $6
         23        DO_ICALL                                                     
         24      > RETURN                                                       1

Function prepared_mysqli_query:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 41
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 50
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 50
Branch analysis from position: 58
Branch analysis from position: 50
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 41
Branch analysis from position: 45
Branch analysis from position: 41
filename:       /in/puKfE
function name:  prepared_mysqli_query
number of ops:  66
compiled vars:  !0 = $query, !1 = $first_half, !2 = $placeholders, !3 = $data_types, !4 = $values, !5 = $trim_end, !6 = $open, !7 = $close, !8 = $values_stripped, !9 = $values_array, !10 = $values_count, !11 = $ph, !12 = $i, !13 = $types, !14 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    6     1        ASSIGN                                                       !1, ''
    7     2        ASSIGN                                                       !2, ''
    8     3        ASSIGN                                                       !3, ''
    9     4        ASSIGN                                                       !4, ''
   12     5        INIT_FCALL                                                   'strrpos'
          6        SEND_VAR                                                     !0
          7        SEND_VAL                                                     '%28'
          8        DO_ICALL                                             $19     
          9        ASSIGN                                                       !5, $19
   13    10        FRAMELESS_ICALL_3                substr              ~21     !0, 0
         11        OP_DATA                                                      !5
         12        ASSIGN                                                       !1, ~21
   16    13        INIT_FCALL                                                   'strrpos'
         14        SEND_VAR                                                     !0
         15        SEND_VAL                                                     '%28'
         16        DO_ICALL                                             $23     
         17        ASSIGN                                                       !6, $23
   17    18        INIT_FCALL                                                   'strrpos'
         19        SEND_VAR                                                     !0
         20        SEND_VAL                                                     '%29'
         21        DO_ICALL                                             $25     
         22        ASSIGN                                                       !7, $25
   19    23        ADD                                                  ~27     !6, 1
         24        ADD                                                  ~28     !7, 1
         25        FRAMELESS_ICALL_3                substr              ~29     !0, ~27
         26        OP_DATA                                                      ~28
         27        ASSIGN                                                       !4, ~29
   20    28        FRAMELESS_ICALL_3                substr              ~31     !4, 0
         29        OP_DATA                                                      -1
         30        ASSIGN                                                       !8, ~31
   21    31        INIT_FCALL                                                   'explode'
         32        SEND_VAL                                                     '%2C'
         33        SEND_VAR                                                     !8
         34        DO_ICALL                                             $33     
         35        ASSIGN                                                       !9, $33
   22    36        COUNT                                                ~35     !9
         37        ASSIGN                                                       !10, ~35
   25    38        ASSIGN                                                       !11, '%28'
   26    39        ASSIGN                                                       !12, 1
         40      > JMP                                                          ->43
   27    41    >   ASSIGN_OP                                         8          !11, '%3F%2C'
   26    42        PRE_INC                                                      !12
         43    >   IS_SMALLER                                                   !12, !10
         44      > JMPNZ                                                        ~41, ->41
   29    45    >   ASSIGN_OP                                         8          !11, '%3F%29'
   30    46        ASSIGN_OP                                         8          !2, !11
   33    47        ASSIGN                                                       !13, ''
   34    48        ASSIGN                                                       !12, 0
         49      > JMP                                                          ->56
   35    50    >   FETCH_DIM_R                                          ~46     !9, 0
         51        GET_TYPE                                             ~47     ~46
         52        ASSIGN                                                       !14, ~47
   36    53        FETCH_DIM_R                                          ~49     !14, 0
         54        ASSIGN_OP                                         8          !13, ~49
   34    55        PRE_INC                                                      !12
         56    >   IS_SMALLER                                                   !12, !10
         57      > JMPNZ                                                        ~52, ->50
   38    58    >   ASSIGN_OP                                         8          !3, !13
   41    59        CONCAT                                               ~54     !1, !2
         60        ASSIGN                                                       !0, ~54
   43    61        INIT_ARRAY                                           ~56     !0, 'query'
   44    62        ADD_ARRAY_ELEMENT                                    ~56     !3, 'data_types'
   45    63        ADD_ARRAY_ELEMENT                                    ~56     !9, 'values'
         64      > RETURN                                                       ~56
   47    65*     > RETURN                                                       null

End of function prepared_mysqli_query

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.51 ms | 2233 KiB | 20 Q