3v4l.org

run code in 300+ PHP versions simultaneously
<?php class database{ // @object, The PDO object private $pdo; private $db_connected, $error; private $stmt; public function __construct($host, $dbname, $user, $pass, $char_set="utf8"){ $dsn = 'mysql:dbname='.$dbname.';host='.$host.''; try{ $this->pdo = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES ".$char_set)); // We can now log any exceptions on Fatal error. $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Disable emulation of prepared statements, use REAL prepared statements instead. $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->db_connected = true; }catch (PDOException $e){ die("Error! Could not connect to the database.<br />".$e->getMessage()); } } public function __destruct(){ $this->pdo = null; $this->db_connected = false; } public function query($query){ try{ $this->stmt = $this->pdo->prepare($query); }catch(PDOException $e){ if( _safemode_ ){ die("Error! Invalid Query.<br />".$query."<br />".$e->getMessage()); } else{ die("A fatal error occurred."); } } } public function bind($param, $value, $type = null){ if ( is_null($type) ){ switch(true){ case is_int($value): $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; case is_null($value): $type = PDO::PARAM_NULL; break; default: $type = PDO::PARAM_STR; } } $this->stmt->bindValue($param, $value, $type); } public function execute(){ try{ $this->stmt->execute(); return true; }catch(PDOException $e){ $this->error = $e->getMessage(); return false; } } public function run(){ $this->execute(); } public function results(){ $this->execute(); return $this->stmt->fetchAll(PDO::FETCH_ASSOC); } public function single(){ $this->execute(); return $this->stmt->fetch(PDO::FETCH_ASSOC); } public function num_rows(){ return $this->stmt->rowCount(); } public function last_insert_id(){ return $this->pdo->lastInsertId(); } public function begin_transaction(){ return $this->pdo->beginTransaction(); } public function end_transaction(){ return $this->pdo->commit(); } public function cancel_transaction(){ return $this->pdo->rollBack(); } public function dump(){ return $this->stmt->debugDumpParams(); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  116     0  E > > RETURN                                                   1

Class database:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 34
Branch analysis from position: 34
2 jumps found. (Code = 107) Position 1 = 35, Position 2 = -2
Branch analysis from position: 35
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/rTv5K
function name:  __construct
number of ops:  40
compiled vars:  !0 = $host, !1 = $dbname, !2 = $user, !3 = $pass, !4 = $char_set, !5 = $dsn, !6 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV_INIT                                        !4      'utf8'
   13     5        CONCAT                                           ~7      'mysql%3Adbname%3D', !1
          6        CONCAT                                           ~8      ~7, '%3Bhost%3D'
          7        CONCAT                                           ~9      ~8, !0
          8        CONCAT                                           ~10     ~9, ''
          9        ASSIGN                                                   !5, ~10
   17    10        NEW                                              $13     'PDO'
         11        SEND_VAR_EX                                              !5
         12        SEND_VAR_EX                                              !2
         13        SEND_VAR_EX                                              !3
         14        FETCH_CLASS_CONSTANT                             ~14     'PDO', 'MYSQL_ATTR_INIT_COMMAND'
         15        CONCAT                                           ~15     'SET+NAMES+', !4
         16        INIT_ARRAY                                       ~16     ~15, ~14
         17        SEND_VAL_EX                                              ~16
         18        DO_FCALL                                      0          
         19        ASSIGN_OBJ                                               'pdo'
         20        OP_DATA                                                  $13
   20    21        FETCH_OBJ_R                                      ~18     'pdo'
         22        INIT_METHOD_CALL                                         ~18, 'setAttribute'
         23        SEND_VAL_EX                                              3
         24        SEND_VAL_EX                                              2
         25        DO_FCALL                                      0          
   23    26        FETCH_OBJ_R                                      ~20     'pdo'
         27        INIT_METHOD_CALL                                         ~20, 'setAttribute'
         28        SEND_VAL_EX                                              20
         29        SEND_VAL_EX                                              <false>
         30        DO_FCALL                                      0          
   25    31        ASSIGN_OBJ                                               'db_connected'
         32        OP_DATA                                                  <true>
         33      > JMP                                                      ->39
   27    34  E > > CATCH                                       last         'PDOException'
   28    35    >   INIT_METHOD_CALL                                         !6, 'getMessage'
         36        DO_FCALL                                      0  $23     
         37        CONCAT                                           ~24     'Error%21+Could+not+connect+to+the+database.%3Cbr+%2F%3E', $23
         38      > EXIT                                                     ~24
   31    39    > > RETURN                                                   null

End of function __construct

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  __destruct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN_OBJ                                               'pdo'
          1        OP_DATA                                                  null
   36     2        ASSIGN_OBJ                                               'db_connected'
          3        OP_DATA                                                  <false>
   37     4      > RETURN                                                   null

End of function __destruct

Function query:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 8
Branch analysis from position: 8
2 jumps found. (Code = 107) Position 1 = 9, Position 2 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/rTv5K
function name:  query
number of ops:  20
compiled vars:  !0 = $query, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        FETCH_OBJ_R                                      ~3      'pdo'
          2        INIT_METHOD_CALL                                         ~3, 'prepare'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $4      
          5        ASSIGN_OBJ                                               'stmt'
          6        OP_DATA                                                  $4
          7      > JMP                                                      ->19
   43     8  E > > CATCH                                       last         'PDOException'
   44     9    >   FETCH_CONSTANT                                   ~5      '_safemode_'
         10      > JMPZ                                                     ~5, ->18
         11    >   CONCAT                                           ~6      'Error%21+Invalid+Query.%3Cbr+%2F%3E', !0
         12        CONCAT                                           ~7      ~6, '%3Cbr+%2F%3E'
         13        INIT_METHOD_CALL                                         !1, 'getMessage'
         14        DO_FCALL                                      0  $8      
         15        CONCAT                                           ~9      ~7, $8
         16      > EXIT                                                     ~9
         17*       JMP                                                      ->19
   45    18    > > EXIT                                                     'A+fatal+error+occurred.'
   47    19    > > RETURN                                                   null

End of function query

Function bind:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 19
filename:       /in/rTv5K
function name:  bind
number of ops:  26
compiled vars:  !0 = $param, !1 = $value, !2 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   50     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~3, ->19
   52     5    >   TYPE_CHECK                                   16          !1
          6      > JMPNZ                                                    ~5, ->12
   55     7    >   TYPE_CHECK                                   12          !1
          8      > JMPNZ                                                    ~6, ->14
   58     9    >   TYPE_CHECK                                    2          !1
         10      > JMPNZ                                                    ~7, ->16
         11    > > JMP                                                      ->18
   53    12    >   ASSIGN                                                   !2, 1
   54    13      > JMP                                                      ->19
   56    14    >   ASSIGN                                                   !2, 5
   57    15      > JMP                                                      ->19
   59    16    >   ASSIGN                                                   !2, 0
   60    17      > JMP                                                      ->19
   62    18    >   ASSIGN                                                   !2, 2
   65    19    >   FETCH_OBJ_R                                      ~12     'stmt'
         20        INIT_METHOD_CALL                                         ~12, 'bindValue'
         21        SEND_VAR_EX                                              !0
         22        SEND_VAR_EX                                              !1
         23        SEND_VAR_EX                                              !2
         24        DO_FCALL                                      0          
   66    25      > RETURN                                                   null

End of function bind

Function execute:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 5
Branch analysis from position: 5
2 jumps found. (Code = 107) Position 1 = 6, Position 2 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  execute
number of ops:  12
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   FETCH_OBJ_R                                      ~1      'stmt'
          1        INIT_METHOD_CALL                                         ~1, 'execute'
          2        DO_FCALL                                      0          
   71     3      > RETURN                                                   <true>
          4*       JMP                                                      ->11
   72     5  E > > CATCH                                       last         'PDOException'
   73     6    >   INIT_METHOD_CALL                                         !0, 'getMessage'
          7        DO_FCALL                                      0  $4      
          8        ASSIGN_OBJ                                               'error'
          9        OP_DATA                                                  $4
   74    10      > RETURN                                                   <false>
   76    11*     > RETURN                                                   null

End of function execute

Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  run
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   INIT_METHOD_CALL                                         'execute'
          1        DO_FCALL                                      0          
   80     2      > RETURN                                                   null

End of function run

Function results:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  results
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   INIT_METHOD_CALL                                         'execute'
          1        DO_FCALL                                      0          
   84     2        FETCH_OBJ_R                                      ~1      'stmt'
          3        INIT_METHOD_CALL                                         ~1, 'fetchAll'
          4        SEND_VAL_EX                                              2
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   85     7*     > RETURN                                                   null

End of function results

Function single:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  single
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   INIT_METHOD_CALL                                         'execute'
          1        DO_FCALL                                      0          
   89     2        FETCH_OBJ_R                                      ~1      'stmt'
          3        INIT_METHOD_CALL                                         ~1, 'fetch'
          4        SEND_VAL_EX                                              2
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   90     7*     > RETURN                                                   null

End of function single

Function num_rows:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  num_rows
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   FETCH_OBJ_R                                      ~0      'stmt'
          1        INIT_METHOD_CALL                                         ~0, 'rowCount'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   94     4*     > RETURN                                                   null

End of function num_rows

Function last_insert_id:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  last_insert_id
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   FETCH_OBJ_R                                      ~0      'pdo'
          1        INIT_METHOD_CALL                                         ~0, 'lastInsertId'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   98     4*     > RETURN                                                   null

End of function last_insert_id

Function begin_transaction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  begin_transaction
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  101     0  E >   FETCH_OBJ_R                                      ~0      'pdo'
          1        INIT_METHOD_CALL                                         ~0, 'beginTransaction'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
  102     4*     > RETURN                                                   null

End of function begin_transaction

Function end_transaction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  end_transaction
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  105     0  E >   FETCH_OBJ_R                                      ~0      'pdo'
          1        INIT_METHOD_CALL                                         ~0, 'commit'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
  106     4*     > RETURN                                                   null

End of function end_transaction

Function cancel_transaction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  cancel_transaction
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   FETCH_OBJ_R                                      ~0      'pdo'
          1        INIT_METHOD_CALL                                         ~0, 'rollBack'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
  110     4*     > RETURN                                                   null

End of function cancel_transaction

Function dump:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTv5K
function name:  dump
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     0  E >   FETCH_OBJ_R                                      ~0      'stmt'
          1        INIT_METHOD_CALL                                         ~0, 'debugDumpParams'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
  114     4*     > RETURN                                                   null

End of function dump

End of class database.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.97 ms | 1406 KiB | 13 Q