Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Database Error on index.php
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Support

2025-08-19 10:17:54
Hi all
I found an error in the index.php file.

Database Error. Please report this to an administrator.


It will be related to the mysql class.phpfile. line 102

How do I fix this?

My server:
Mysql Version: 10.6.17-MariaDB-cll-lve
PHP Version: 7.2.34
Apache Version: LiteSpeed

Thanks guys
mysql.class.php
Download
Last edited by ziannoi on 2025-08-19 10:24:08
2025-08-19 21:48:58
Hi ziannoi ;)

Test my file, it's fine for me #1


mysql.class.zip
Download

2025-08-19 23:06:08
there is nothing wrong with that class file, you made a bad edit somewhere and its calling a function in that file and crashing. Its not that file. Check whatever edits you recently did
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2025-08-19 23:07:08
2025-08-22 20:27:07
Here is my mysql.class  
<?php function SQL_Query(string $query) {
   return new SQL_Query($query);
}

function SQL_Query_exec(string $query) {
   try {
       $sql = new SQL_Query($query);
       return $sql->execute();
   } catch (Exception $e) {
       error_log("SQL Query Execution Error: " . $e->getMessage());
       return null;
   }
}

class SQL_Query {
   private string $query = "";
   private array $params = [];

   public function __construct(string $query) {
       $this->query = $query;
       return $this;
   }

   public function p($param) {
       if (is_numeric($param)) {
           $this->params[] = $param;
       } elseif (is_array($param)) {
           $this->params[] = implode(", ", array_map([$this, "escape"], $param));
       } else {
           $this->params[] = $this->escape($param);
       }
       return $this;
   }

   public function p_name(string $param) {
       $this->params[] = "`" . mysqli_real_escape_string($GLOBALS["DBconnector"], $param) . "`";
       return $this;
   }

   public function escape($s) {
       if (is_numeric($s)) {
           return $s;
       }
       return "'" . mysqli_real_escape_string($GLOBALS["DBconnector"], $s) . "'";
   }

   public function read() {
       $ret = "";
       if (count($this->params)) {
           reset($this->params);
           for ($i = 0; $i < strlen($this->query); $i++) {
               if ($this->query[$i] == "?") {
                   $val = current($this->params);
                   next($this->params);
                   $ret .= $val;
               } else {
                   $ret .= $this->query[$i];
               }
           }
           reset($this->params);
       } else {
           $ret = $this->query;
       }
       return $ret;
   }

   public function execute() {
       $query = $this->read();
       $res = mysqli_query($GLOBALS["DBconnector"], $query);

       if ($res || mysqli_errno($GLOBALS["DBconnector"]) == 1062) {
           return $res;
       }
       $mysqli_error = mysqli_error($GLOBALS["DBconnector"]);
       $mysqli_errno = mysqli_errno($GLOBALS["DBconnector"]);

       if (function_exists("debug_backtrace")) {
           $bt = debug_backtrace();
           $i = 1;
           if ($bt[$i]["function"] == "SQL_Query_exec_cached" || $bt[$i]["function"] == "get_row_count_cached" || $bt[$i]["function"] == "get_row_count") {
               $i++;
           }
           $line = $bt[$i]["line"];
           $file = str_replace(getcwd() . DIRECTORY_SEPARATOR, "", $bt[$i]["file"]);
           $msg = "Database Error in $file on line $line: $mysqli_error. Query was: $query.";
       } else {
           $file = str_replace(getcwd() . DIRECTORY_SEPARATOR, "", $_SERVER["SCRIPT_FILENAME"]);
           $msg = "Database Error in $file: $mysqli_error. Query was: $query";
       }

       mysqli_query($GLOBALS["DBconnector"], "INSERT INTO `sqlerr` (`txt`, `time`)
                    VALUES (" . sqlesc($msg) . ", '" . get_date_time() . "')");

       show_error_msg("Database Error", "Database Error. Please report this to an administrator.", 1);

       return null;
   }
}
?>

TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2025-08-23 17:18:12
2025-08-24 08:37:20
Thanks for the advice, I fixed it now. 👍
2025-09-05 16:25:16
Potential Problem:
--------------------------------------
return $this; 

in __construct

In PHP, a constructor (__construct) must not return a value.
The purpose of a constructor is only to initialize the object when it is created.

Since PHP 8, if you write return $this; (or return anything) inside __construct, PHP will trigger a Deprecated notice.

In future versions, this will likely become a Fatal error and immediately break execution.

Wrong (current code)

public function __construct(string $query) {
   $this->query = $query;
   return $this; // Not allowed in PHP 8+
}


Correct (safe for PHP 8.4+)

public function __construct(string $query) {
   $this->query = $query;
   // no return statement here
}


Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 3
  • Members: 0
  • Guests online: 3
  • Comments: 3
  • Messages: 1,728