Advertisement
Guest User

db.class.php

a guest
Oct 20th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.48 KB | None | 0 0
  1. <?php
  2. class Clipbucket_db
  3. {
  4.     /** @var mysqli $mysqli */
  5.     var $mysqli = '';
  6.  
  7.     var $db_name = '';
  8.     var $db_uname = '';
  9.     var $db_pwd = '';
  10.     var $db_host = '';
  11.  
  12.     var $total_queries_sql = [];
  13.     var $total_queries = 0;
  14.  
  15.     /**
  16.      * Connect to mysqli Database
  17.      *
  18.      * @param $host
  19.      * @param $name
  20.      * @param $uname
  21.      * @param $pwd
  22.      *
  23.      * @return bool|void
  24.      *
  25.      * @internal param $ : { string } { $host } { your database host e.g localhost }
  26.      * @internal param $ : { string } { $name } { name of database to connect to }
  27.      * @internal param $ : { string } { $uname } { your database username }
  28.      * @internal param $ : { string } { $pwd } { password of database to connect to }
  29.      */
  30.     function connect($host = '', $name = '', $uname = '', $pwd = '')
  31.     {
  32.         try {
  33.             if (!$host) {
  34.                 $host = $this->db_host;
  35.             } else {
  36.                 $this->db_host = $host;
  37.             }
  38.  
  39.             if (!$name) {
  40.                 $name = $this->db_name;
  41.             } else {
  42.                 $this->db_name = $name;
  43.             }
  44.  
  45.             if (!$uname) {
  46.                 $uname = $this->db_uname;
  47.             } else {
  48.                 $this->db_uname = $uname;
  49.             }
  50.  
  51.             if (!$pwd) {
  52.                 $pwd = $this->db_pwd;
  53.             } else {
  54.                 $this->db_pwd = $pwd;
  55.             }
  56.  
  57.             $this->mysqli = new mysqli($host, $uname, $pwd, $name);
  58.             if ($this->mysqli->connect_errno) {
  59.                 return false;
  60.             }
  61.  
  62.             $this->execute('SET NAMES "utf8mb4"');
  63.         } catch (\Exception $e) {
  64.             $error = $e->getMessage();
  65.             error_log($error);
  66.             if (in_dev()) {
  67.                 die($error);
  68.             }
  69.         }
  70.     }
  71.  
  72.     /**
  73.      * Select elements from database with query
  74.      *
  75.      * @param : { string } { $query } { mysql query to run }
  76.      *
  77.      * @return array : { array } { $data } { array of selected data }
  78.      * @throws Exception
  79.      */
  80.     function _select($query, $cached_time = -1, $cached_key = ''): array
  81.     {
  82.         try {
  83.             $redis = CacheRedis::getInstance();
  84.             if ($redis->isEnabled() && $cached_time != -1) {
  85.                 if (in_dev()) {
  86.                     $start = microtime(true);
  87.                     $return = $redis->get($cached_key . ':' . $query);
  88.                     $end = microtime(true);
  89.                     $timetook = $end - $start;
  90.                     if (!empty($return)) {
  91.                         devWitch($query, 'select', $timetook, true);
  92.                     }
  93.                 } else {
  94.                     $return = $redis->get($cached_key . ':' . $query);
  95.                 }
  96.  
  97.                 if (!empty($return)) {
  98.                     return $return;
  99.                 }
  100.             }
  101.             $result = $this->execute($query, 'select');
  102.             $data = [];
  103.             if ($result) {
  104.                 while ($row = $result->fetch_assoc()) {
  105.                     $data[] = $row;
  106.                 }
  107.                 $result->close();
  108.             }
  109.  
  110.             if ($redis->isEnabled() && $cached_time != -1 && !empty($data)) {
  111.                 $redis->set($cached_key.':'.$query, $data, $cached_time);
  112.             }
  113.         } catch (\Exception $e) {
  114.             if ($e->getMessage() == 'lang_not_installed' || $e->getMessage() == 'version_not_installed') {
  115.                 throw $e;
  116.             }
  117.             $this->handleError($query);
  118.         }
  119.         return $data;
  120.     }
  121.  
  122.     /**
  123.      * Select elements from database with numerous conditions
  124.      *
  125.      * @param : { string } { $tbl } { table to select data from }
  126.      * @param string $fields
  127.      * @param bool $cond
  128.      * @param bool $limit
  129.      * @param bool $order
  130.      * @param bool $ep
  131.      *
  132.      * @return array : { array } { $data } { array of selected data }
  133.      * @throws Exception
  134.      */
  135.     function select($tbl, $fields = '*', $cond = false, $limit = false, $order = false, $ep = false, $cached_time = -1, $cached_key = ''): array
  136.     {
  137.         $query_params = '';
  138.  
  139.         if ($cond) {
  140.             $query_params .= ' WHERE ' . $cond;
  141.         }
  142.         if ($order) {
  143.             $query_params .= ' ORDER BY ' . $order;
  144.         }
  145.         if ($limit) {
  146.             $query_params .= ' LIMIT ' . $limit;
  147.         }
  148.  
  149.         $query = 'SELECT ' . $fields . ' FROM ' . $tbl . $query_params . ' ' . $ep;
  150.         return $this->_select($query, $cached_time, $cached_key);
  151.     }
  152.  
  153.     /**
  154.      * Count values in given table using MySQL COUNT
  155.      *
  156.      * @param : { string }   { $tbl } { table to count data from }
  157.      * @param string $fields
  158.      * @param bool $cond
  159.      *
  160.      * @return bool|int
  161.      * @throws Exception
  162.      */
  163.     function count($tbl, $fields = '*', $cond = false, $ep = '',$cached_time = -1, $cached_key = '')
  164.     {
  165.         $condition = '';
  166.         if ($cond) {
  167.             $condition = ' WHERE ' . $cond;
  168.         }
  169.         $query = 'SELECT COUNT(' . $fields . ') FROM ' . $tbl . $condition . $ep;
  170.  
  171.         $result = $this->_select($query, $cached_time, $cached_key);
  172.  
  173.         if ($result) {
  174.             $fields = $result[0];
  175.             foreach ($fields as $field) {
  176.                 return $field;
  177.             }
  178.         }
  179.  
  180.         return false;
  181.     }
  182.  
  183.     /**
  184.      * Get row using query
  185.      *
  186.      * @param : { string } { $query } { query to run to get row }
  187.      *
  188.      * @return mixed
  189.      * @throws Exception
  190.      */
  191.     function GetRow($query)
  192.     {
  193.         $result = $this->_select($query);
  194.         if ($result) {
  195.             return $result[0];
  196.         }
  197.     }
  198.  
  199.     /**
  200.      * Execute a MYSQL query directly without processing
  201.      *
  202.      * @param : { string } { $query } { query that you want to execute }
  203.      *
  204.      * @return bool|mysqli_result
  205.      * @throws Exception
  206.      */
  207.     function execute($query, $type = 'execute')
  208.     {
  209.         $this->ping();
  210.  
  211.         try {
  212.             if (in_dev()) {
  213.                 $start = microtime(true);
  214.                 $data = $this->mysqli->query($query);
  215.                 $end = microtime(true);
  216.                 $timetook = $end - $start;
  217.                 devWitch($query, $type, $timetook, false);
  218.             } else {
  219.                 $data = $this->mysqli->query($query);
  220.             }
  221.             $this->handleError($query);
  222.             return $data;
  223.         } catch (\Exception $e) {
  224.             if ($e->getMessage() == 'lang_not_installed' || $e->getMessage() == 'version_not_installed') {
  225.                 throw $e;
  226.             }
  227.             $this->handleError($query);
  228.         }
  229.         return false;
  230.     }
  231.  
  232.     /**
  233.      * Update database fields { table, fields, values style }
  234.      *
  235.      * @param      $tbl
  236.      * @param      $flds
  237.      * @param      $vls
  238.      * @param      $cond
  239.      * @param null $ep
  240.      *
  241.      * @throws Exception
  242.      * @internal param $ : { string } { $tbl } { table to ujpdate values in }
  243.      * @internal param $ : { array } { $flds } { array of fields you want to update }
  244.      * @internal param $ : { array } { $vls } { array of values to update against fields }
  245.      * @internal param $ : { string } { $cond } { mysql condition for query }
  246.      * @internal param $ : { string } { $ep } { extra parameter after condition }
  247.      */
  248.     function update($tbl, $flds, $vls, $cond, $ep = null)
  249.     {
  250.         $this->ping();
  251.  
  252.         $total_fields = count($flds);
  253.         $count = 0;
  254.         $fields_query = '';
  255.         for ($i = 0; $i < $total_fields; $i++) {
  256.             $count++;
  257.             $val = ($vls[$i]);
  258.             preg_match('/\|no_mc\|/', $val, $matches);
  259.             if ($matches) {
  260.                 $val = preg_replace('/\|no_mc\|/', '', $val);
  261.             } else {
  262.                 $val = $this->clean_var($val);
  263.             }
  264.  
  265.             $needle = substr($val, 0, 3);
  266.             if ($needle != '|f|') {
  267.                 $fields_query .= $flds[$i] . "='" . $val . "'";
  268.             } else {
  269.                 $val = substr($val, 3, strlen($val));
  270.                 $fields_query .= $flds[$i] . '=' . $val;
  271.             }
  272.  
  273.             if ($total_fields != $count) {
  274.                 $fields_query .= ',';
  275.             }
  276.         }
  277.         //Complete Query
  278.         $query = 'UPDATE ' . $tbl . ' SET ' . $fields_query . ' WHERE ' . $cond . ' ' . $ep;
  279.        
  280.         $this->execute($query, 'update');
  281.     }
  282.    
  283. function updateSpecialCase($tbl, $key, $value)
  284. {
  285.     $this->ping();
  286.    
  287.     if (is_array($key) && is_array($value) && count($key) === count($value)) {
  288.         $updates = [];
  289.         for ($i = 0; $i < count($key); $i++) {
  290.             $cleanedValue = preg_replace('/\|no_mc\|/', '', $value[$i]);
  291.             $cleanedValue = ($cleanedValue[0] != '|') ? $this->clean_var($cleanedValue) : substr($cleanedValue, 1);
  292.             $updates[] = $key[$i] . "='" . $cleanedValue . "'";
  293.         }
  294.        
  295.         $fieldsQuery = implode(',', $updates);
  296.        
  297.         $query = 'UPDATE ' . $tbl . ' SET ' . $fieldsQuery;
  298.        
  299.         $this->execute($query, 'update');
  300.     } else {
  301.         // Handle the case when $key and $value are not arrays of the same length.
  302.         // You can log an error, throw an exception, or perform other error handling.
  303.         // For example:
  304.         error_log('Error: $key and $value must be arrays!.');
  305.         // You can also throw an exception:
  306.         // throw new Exception('$key and $value must be arrays of the same length');
  307.     }
  308. }
  309.  
  310. function updateUser2FACheckBoxState($usersTable, $inputUserId, $inputUser2FACheckboxState) {
  311.     $QueryFor2FACheckBox = "SELECT user2FAstate, user2FAconfigstate FROM $usersTable WHERE user2FAstate = 0 AND user2FAconfigstate = 0 AND userid = $inputUserId";
  312.     $result = $this->execute($QueryFor2FACheckBox, 'select');
  313.  
  314.     if ($result !== false) {
  315.         $row_count = mysqli_num_rows($result);
  316.  
  317.         if ($row_count > 0) {
  318.             $updateQuery = "UPDATE $usersTable SET user2FAstate = $inputUser2FACheckboxState, user2FAconfigstate = $inputUser2FACheckboxState WHERE userid = $inputUserId";
  319.             $this->execute($updateQuery, 'update');
  320.         } else {
  321.             error_log( "No rows found with user2FAstate and user2FAconfigstate both equal to 0 for user $inputUserId.");
  322.         }
  323.     } else {
  324.         error_log( "Error executing SELECT query.");
  325.     }
  326. }
  327.  
  328. function getStatusOfUser2FACheckBox($usersTable, $inputUserId): bool {
  329.     $query = "SELECT user2FAstate, user2FAconfigstate FROM $usersTable WHERE userid = $inputUserId";
  330.     $result = $this->execute($query, 'select');
  331.  
  332.     if ($result === false) {
  333.         return false;  // Error executing query, consider this as false
  334.     }
  335.  
  336.     $row = $result->fetch_assoc(); // Fetch the first row as an associative array
  337.  
  338.     if ($row) {
  339.         // Check if both user2FAstate and user2FAconfigstate are equal to 1
  340.         if ($row['user2FAstate'] === '1' && $row['user2FAconfigstate'] === '1') {
  341.             return true;
  342.         }
  343.     }
  344.  
  345.     return false;  // If no rows are returned or conditions not met
  346. }
  347.  
  348. function setUser2FASecretOTP($usersTable, $inputUserID, $inputEncryptedSecureOTP) {
  349.     $CheckIf2FANotSetUp = "SELECT user2FAstate, user2FAconfigstate, user2FAprivatecode FROM $usersTable WHERE userid = $inputUserID AND user2FAstate = 1 AND user2FAconfigstate = 1 AND user2FAprivatecode = 0;";
  350.     $result = $this->execute($CheckIf2FANotSetUp, 'select');
  351.    
  352.     if ($result !== false) {
  353.         $row_count = mysqli_num_rows($result);
  354.  
  355.         if ($row_count > 0) {
  356.             $updateQuery = "UPDATE $usersTable SET user2FAprivatecode = '$inputEncryptedSecureOTP' WHERE userid = $inputUserID";
  357.             $this->execute($updateQuery, 'update');
  358.         } else {
  359.             error_log("No rows found with user2FAstate and user2FAconfigstate and user2FAprivatecode all those rows should be equal to 0 for user $inputUserID.");
  360.         }
  361.     } else {
  362.         error_log("Error executing SELECT query.");
  363.     }
  364. }
  365.  
  366. function getGlobal2FAState($usersTable): bool {
  367.     $Global2FAstateQuery = "SELECT enabled2fa FROM $usersTable WHERE enabled2fa = 1;";
  368.     $result = $this->execute($Global2FAstateQuery, 'select');
  369.  
  370.     if ($result !== false) {
  371.         $row_count = mysqli_num_rows($result);
  372.         return ($row_count > 0); // Returns true if at least one row is found, indicating 2FA is enabled.
  373.     } else {
  374.            error_log("Global 2FA state NOT ENABLED!");
  375.         return false;
  376.     }
  377. }
  378.  
  379. function getUser2FAState($usersTable, $username):bool{
  380.    $Given2FAUserState = "SELECT user2FAstate, user2FAconfigstate, username FROM $usersTable WHERE username = '$username' AND user2FAstate = 1 AND user2FAconfigstate = 1 AND username IS NOT NULL;";
  381.    $result = $this->execute($Given2FAUserState, 'select');
  382.    
  383.    if ($result !== false) {
  384.         $row_count = mysqli_num_rows($result);
  385.         return ($row_count > 0); // Returns true if at least one row is found, indicating 2FA is enabled.
  386.     } else {
  387.            error_log("User: $username 2FA state is NOT ENABLED!");
  388.         return false;
  389.     }
  390. }
  391.  
  392. function getUser2FASecret($usersTable, $username) {
  393.     $Encrypted2FAUserSecretQuery = "SELECT user2FAprivatecode FROM $usersTable WHERE username = '$username' AND user2FAprivatecode IS NOT NULL;";
  394.     $result = $this->execute($Encrypted2FAUserSecretQuery, 'select');
  395.  
  396.     if ($result !== false) {
  397.         $row = mysqli_fetch_assoc($result);
  398.         if ($row && isset($row['user2FAprivatecode'])) {
  399.             return $row['user2FAprivatecode']; // Return the 2FA secret code if it exists and is not null.
  400.         } else {
  401.             error_log("User: $username does not have a valid 2FA secret code.");
  402.             return false;
  403.         }
  404.     } else {
  405.         error_log("Error executing query to retrieve 2FA secret code for user: $username");
  406.         return false;
  407.     }
  408. }
  409.  
  410.  
  411.     /**
  412.      * Update database fields { table, associative array style }
  413.      *
  414.      * @param      $tbl
  415.      * @param      $fields
  416.      * @param      $cond
  417.      * @param null $ep
  418.      *
  419.      * @return bool : { boolean }
  420.      *
  421.      * @throws Exception
  422.      * @internal param $ : { array } { $fields } { associative array with fields and values }
  423.      * @internal param $ : { string } { $cond } { mysql condition for query }
  424.      * @internal param $ : { string } { $tbl } { table to update values in }
  425.      */
  426.     function db_update($tbl, $fields, $cond, $ep = null)
  427.     {
  428.         $this->ping();
  429.  
  430.         $count = 0;
  431.         $fields_query = '';
  432.         foreach ($fields as $field => $val) {
  433.             if ($count > 0) {
  434.                 $fields_query .= ',';
  435.             }
  436.             $needle = substr($val, 0, 2);
  437.             if ($needle != '{{') {
  438.                 $value = "'" . mysql_clean($val) . "'";
  439.             } else {
  440.                 $val = substr($val, 2, strlen($val) - 4);
  441.                 $value = mysql_clean($val);
  442.             }
  443.  
  444.             $fields_query .= $field . "=$value ";
  445.             $count += $count;
  446.         }
  447.         //Complete Query
  448.         $query = 'UPDATE ' . $tbl . ' SET ' . $fields_query . ' WHERE ' . $cond . ' ' . $ep;
  449.         $this->execute($query, 'update');
  450.         return true;
  451.     }
  452.  
  453.     /**
  454.      * Delete an element from database
  455.      *
  456.      * @param      $tbl
  457.      * @param      $flds
  458.      * @param      $vls
  459.      * @param null $ep
  460.      *
  461.      * @throws Exception
  462.      * @internal param $ : { array } { $flds } { array of fields to update }
  463.      * @internal param $ : { array } { $vlds } { array of values to update against fields }
  464.      * @internal param $ : { string } { $ep } { extra parameters to consider }
  465.      * @internal param $ : { string } { $tbl } { table to delete value from }
  466.      */
  467.     function delete($tbl, $flds, $vls, $ep = null)
  468.     {
  469.         $this->ping();
  470.  
  471.         $total_fields = count($flds);
  472.         $fields_query = '';
  473.         $count = 0;
  474.         for ($i = 0; $i < $total_fields; $i++) {
  475.             $count++;
  476.             $val = $this->clean_var($vls[$i]);
  477.             $needle = substr($val, 0, 3);
  478.             if ($needle != '|f|') {
  479.                 $fields_query .= $flds[$i] . "='" . $val . "'";
  480.             } else {
  481.                 $val = substr($val, 3, strlen($val));
  482.                 $fields_query .= $flds[$i] . '=' . $val;
  483.             }
  484.             if ($total_fields != $count) {
  485.                 $fields_query .= ' AND ';
  486.             }
  487.         }
  488.         //Complete Query
  489.         $query = 'DELETE FROM ' . $tbl . ' WHERE ' . $fields_query . ' ' . $ep;
  490.         if (isset($this->total_queries)) {
  491.             $this->total_queries++;
  492.         }
  493.         $this->total_queries_sql[] = $query;
  494.         $this->execute($query, 'delete');
  495.     }
  496.  
  497.     /**
  498.      * Function used to insert values in database { table, fields, values style }
  499.      *
  500.      * @param      $tbl
  501.      * @param      $flds
  502.      * @param      $vls
  503.      * @param null $ep
  504.      *
  505.      * @return mixed|void : { integer } { $insert_id } { id of inserted element }
  506.      *
  507.      * @throws Exception
  508.      * @internal param $ : { string } { $tbl } { table to insert values in }
  509.      * @internal param $ : { array } { $flds } { array of fields to update }
  510.      * @internal param $ : { array } { $vlds } { array of values to update against fields }
  511.      * @internal param $ : { string } { $ep } { extra parameters to consider }
  512.      */
  513.     function insert($tbl, $flds, $vls, $ep = null)
  514.     {
  515.         $this->ping();
  516.  
  517.         $total_fields = count($flds);
  518.         $count = 0;
  519.         $fields_query = '';
  520.         $values_query = '';
  521.         foreach ($flds as $field) {
  522.             $count++;
  523.             $fields_query .= $field;
  524.             if ($total_fields != $count) {
  525.                 $fields_query .= ',';
  526.             }
  527.         }
  528.         $total_values = count($vls);
  529.         $count = 0;
  530.         foreach ($vls as $value) {
  531.             $count++;
  532.             preg_match('/\|no_mc\|/', $value, $matches);
  533.             if ($matches) {
  534.                 $val = preg_replace('/\|no_mc\|/', '', $value);
  535.             } else {
  536.                 $val = $this->clean_var($value);
  537.             }
  538.             if (strtoupper($val) == 'NULL') {
  539.                 $values_query .= 'NULL';
  540.             } else {
  541.                 $needle = substr($val, 0, 3);
  542.                 if ($needle != '|f|') {
  543.                     $values_query .= "'" . $val . "'";
  544.                 } else {
  545.                     $val = substr($val, 3, strlen($val));
  546.                     $values_query .= "'" . $val . "'";
  547.                 }
  548.             }
  549.  
  550.             if ($total_values != $count) {
  551.                 $values_query .= ',';
  552.             }
  553.         }
  554.         $query = "INSERT INTO $tbl ($fields_query) VALUES ($values_query) $ep";
  555.         $this->total_queries_sql[] = $query;
  556.         if (isset($this->total_queries)) {
  557.             $this->total_queries++;
  558.         }
  559.  
  560.         try {
  561.             $this->mysqli->query($query);
  562.             $this->handleError($query);
  563.             return $this->insert_id();
  564.         } catch (\Exception $e) {
  565.             $this->handleError($query);
  566.         }
  567.  
  568.     }
  569.  
  570.     /**
  571.      * Function used to insert values in database { table, associative array style }
  572.      *
  573.      * @param $tbl
  574.      * @param $fields
  575.      *
  576.      * @return mixed : { integer } { $insert_id } { id of inserted element }
  577.      *
  578.      * @throws Exception
  579.      * @internal param $ : { array } { $flds } { array of fields and values to update (associative array) }
  580.      * @internal param $ : { string } { $tbl } { table to insert values in }
  581.      */
  582.     function db_insert($tbl, $fields)
  583.     {
  584.         $this->ping();
  585.  
  586.         $count = 0;
  587.         $query_fields = [];
  588.         $query_values = [];
  589.         foreach ($fields as $field => $val) {
  590.             $query_fields[] = $field;
  591.             $needle = substr($val, 0, 2);
  592.             if ($needle != '{{') {
  593.                 $query_values[] = "'" . mysql_clean($val) . "'";
  594.             } else {
  595.                 $val = substr($val, 2, strlen($val) - 4);
  596.                 $query_values[] = mysql_clean($val);
  597.             }
  598.  
  599.             $count += $count;
  600.         }
  601.  
  602.         $fields_query = implode(',', $query_fields);
  603.         $values_query = implode(',', $query_values);
  604.         //Complete Query
  605.         $query = "INSERT INTO $tbl ($fields_query) VALUES ($values_query) $ep";
  606.         $this->total_queries++;
  607.         $this->total_queries_sql[] = $query;
  608.         try {
  609.             $this->mysqli->query($query);
  610.  
  611.             $this->handleError($query);
  612.             return $this->insert_id();
  613.         } catch (\Exception $e) {
  614.             $this->handleError($query);
  615.         }
  616.     }
  617.  
  618.     /**
  619.      * Returns last insert id.
  620.      *
  621.      * Always use this right after calling insert method or before
  622.      * making another mysqli query.
  623.      *
  624.      * @return mixed
  625.      */
  626.     function insert_id()
  627.     {
  628.         return $this->mysqli->insert_id;
  629.     }
  630.  
  631.     /**
  632.      * Clean variable for mysql
  633.      *
  634.      * @param $var
  635.      *
  636.      * @return string
  637.      */
  638.     function clean_var($var): string
  639.     {
  640.         $this->ping();
  641.         return $this->mysqli->real_escape_string($var);
  642.     }
  643.  
  644.     /**
  645.      * @param $query
  646.      * @return void
  647.      * @throws Exception
  648.      */
  649.     private function handleError($query)
  650.     {
  651.         if ($this->getError() != '') {
  652.             //customize exceptions
  653.             if (preg_match('/language.*doesn\'t exist/', $this->getError())) {
  654.                 throw new \Exception("lang_not_installed");
  655.             }
  656.             if (preg_match('/version.*doesn\'t exist/', $this->getError())) {
  657.                 throw new \Exception("version_not_installed");
  658.             }
  659.             if (preg_match('/doesn\'t exist/', $this->getError())) {
  660.                 throw new \Exception("missing_table");
  661.             }
  662.  
  663.             if (in_dev()) {
  664.                 e('SQL : ' . $query);
  665.                 e('ERROR : ' . $this->getError());
  666.                 error_log('SQL : ' . $query);
  667.                 error_log('ERROR : ' . $this->getError());
  668.                 error_log(debug_backtrace_string());
  669.             } else {
  670.                 e(lang('technical_error'));
  671.             }
  672.         }
  673.     }
  674.  
  675.     private function ping()
  676.     {
  677.         if (!$this->mysqli->ping()) {
  678.             error_log('SQL ERROR : ' . $this->mysqli->error);
  679.             $this->connect();
  680.         }
  681.     }
  682.  
  683.     /**
  684.      * Get effect rows
  685.      */
  686.     function Affected_Rows()
  687.     {
  688.         return $this->mysqli->affected_rows;
  689.     }
  690.  
  691.     function getError()
  692.     {
  693.         return $this->mysqli->error;
  694.     }
  695.  
  696. }
  697.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement