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
Php 7 database connector functions
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / General / Tutorials

2019-03-16 20:35:31
This post assumes you are using TT v3.0 that uses a database connector that I named DBconnector. Its not named that for any particular reason, you can call it shittyshit if you like lol. I named it DBconnector so it would make sense as to what it is if you are reading the code.

These are functions that need to have the DBconnector added to them. if you can think of more, add them.
Example:
if (mysql_errno() == 1062)

becomes
if (mysqli_errno($GLOBALS["DBconnector"]) == 1062)


You can just copy/paste $GLOBALS["DBconnector"] into your new functions

mysqli_affected_rows
mysqli_insert_id
mysqli_errno
mysqli_error
mysqli_query
mysqli_close
mysqli_real_escape_string

Example:
$reason = mysql_real_escape_string($_POST["reason"]);

becomes
$reason = mysqli_real_escape_string($GLOBALS["DBconnector"], $_POST["reason"]);


mysqli_connect_error does NOT need it


For reference, This is what I added to the backend/functions.php file to emulate these functions listed below this stupid sentence.
each()
mysql_result()

I did this so that using old mods would be easier to integrate into php 7.  Those functions can be completely rewritten, but for the sake of trying the easy way, I did this

each()  uses a new function written into the backend/functions.php file near the top. All instance of each() should be changed to thisEach()
mysql_result is also emulated in the backend/functions.php near the top. Just change all mysql_result to mysqli_result and it will be emulated since there is no such function in php.

/// each() replacement for php 7+. Change all instances of each() to thisEach() in all TT files. each() deprecated as of 7.2
function thisEach(&$arr) {
   $key = key($arr);
   $result = ($key === null) ? false : [$key, current($arr), 'key' => $key, 'value' => current($arr)];
   next($arr);
   return $result;
}
///end each() replacement

///mysql_result replacement for php 7+. Change all mysql_result to mysqli_result in all TT files. mysql_result deprercated/removed, so emulate it. Should switch to data_seek
function mysqli_result($res,$row=0,$col=0){
   $numrows = mysqli_num_rows($res);
   if ($numrows && $row <= ($numrows-1) && $row >=0){
       mysqli_data_seek($res,$row);
       $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
       if (isset($resrow[$col])){
           return $resrow[$col];
       }
   }
   return false;
}
///end mysql_result replacement

function thisEach() has been removed and rewritten in TTv3. Thanks to M-Jay
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 2023-01-09 04:09:36
2022-06-18 12:02:01
Cheers for that, i will give it a try and see what happens lol
2022-06-18 13:29:26
thank you very much for this tutorial  👍
2022-06-19 17:40:30
The answer to this is using a pointer instead. Example:

foreach ($array as $foo => &$var) {
}


No need for Each().
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: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728