Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   TBDev (http://www.bvlist.com/forumdisplay.php?f=20)
-   -   function dbconn (http://www.bvlist.com/showthread.php?t=12357)

elvira 29th April 2021 18:09

function dbconn
 
Hello all,


need little help here, so these fuctions need to be mysqli


Code:

function dbconn_announce() {
    global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;

    if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass))
    {
        die('dbconn: mysql_connect: ' . mysql_error());
    }
    mysql_query("SET NAMES UTF8");
    mysql_query("SET collation_connection = 'utf8_general_ci'");
    mysql_query("SET sql_mode=''");
    mysql_select_db($mysql_db) or die('dbconn: mysql_select_db: ' + mysql_error());
}


and this one


Code:

function dbconn($autoclean = false)
{
    global $lang_functions;
    global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
    global $useCronTriggerCleanUp;

    if (!mysql_connect($mysql_host, $mysql_user, $mysql_pass))
    {
        switch (mysql_errno())
        {
            case 1040:
            case 2002:
                die("

".$lang_functions['std_server_load_very_high']."

");
            default:
                die("[" . mysql_errno() . "] dbconn: mysql_connect: " . mysql_error());
        }
    }
    mysql_query("SET NAMES UTF8");
    mysql_query("SET collation_connection = 'utf8_general_ci'");
    mysql_query("SET sql_mode=''");
    mysql_select_db($mysql_db) or die('dbconn: mysql_select_db: ' + mysql_error());

    userlogin();

    if (!$useCronTriggerCleanUp && $autoclean) {
        register_shutdown_function("autoclean");
    }
}

and this one

Code:

function sql_query($query)
{
        global $query_name;
        $query_name[] = $query;
        return mysql_query($query);
}

Thank you for help

darkalchemy 30th April 2021 00:52

Without doing the rewrite for you, start by changing mysql to mysqli, in the code.

The connection signature changes to this:
Code:

mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
Also, I would move these to you mysql.conf file, it will save you 3 queries with every connection.
Code:

mysql_query("SET NAMES UTF8");
mysql_query("SET collation_connection = 'utf8_general_ci'");
mysql_query("SET sql_mode=''");

and you can remove this, as it's now part of the connection signature, saving another query with every connection.
Code:

mysql_select_db($mysql_db) or die('dbconn: mysql_select_db: ' + mysql_error());
Also, you will need to pass the database connection to mysqli_query like:
Code:

mysqli_query($db, $query);
You can make the $db connection a global or fetch it as needed.

xblade 30th April 2021 09:28

also this will not work on seedbox and home pc torrents On cleanups
you will get DB locks on it via mysqli it will only work on PHP 5.6 NOT 7.0 SO ON

PHP Code:

    $fields explode(":""comments:leechers:seeders");
    
$res sql_query("SELECT id, seeders, leechers, comments FROM torrents");
    while (
$row mysqli_fetch_assoc($res)) {
        
$id $row["id"];
        
$torr $torrents[$id];
        foreach (
$fields as $field) {
            if (!isset(
$torr[$field]))
                
$torr[$field] = 0;
        }
        
$update = array();
        foreach (
$fields as $field) {
            if (
$torr[$field] != $row[$field])
                
$update[] = "$field = " $torr[$field];
        }
        if (
count($update))
            
sql_query("UPDATE torrents SET " implode(","$update) . " WHERE id = $id");
    } 


elvira 30th April 2021 18:05

I have something like this


Code:

function dbconn($autoclean = false)
{
    global $lang_functions;
    global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
    global $useCronTriggerCleanUp;

    if (!@($GLOBALS["___mysqli_ston"] = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_db)))
    {
        switch (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_errno($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_errno()) ? $___mysqli_res : false)))
        {
            case 1040:
            case 2002:
                die("

".$lang_functions['std_server_load_very_high']."

");
            default:
                die("[" . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_errno($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_errno()) ? $___mysqli_res : false)) . "] dbconn: mysql_connect: " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
        }
    }
    mysqli_query($GLOBALS['___mysqli_ston'], "SET NAMES UTF8");
    mysqli_query($GLOBALS['___mysqli_ston'], "SET collation_connection = 'utf8_general_ci'");
    mysqli_query($GLOBALS['___mysqli_ston'], "SET sql_mode=''");
    //mysql_select_db($mysql_db) or die('dbconn: mysql_select_db: ' + mysql_error());
  ((bool)mysqli_query($GLOBALS['___mysqli_ston'], "USE " . $mysql_db)) or die('dbconn: mysql_select_db: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

    userlogin();

    if (!$useCronTriggerCleanUp && $autoclean) {
        register_shutdown_function("autoclean");
    }
}


xblade 2nd May 2021 08:59

what TBDev are u using this would help me with you ?

Elena 2nd May 2021 09:22

Quote:

Originally Posted by elvira (Post 55467)
Hello all,
need little help here, so these fuctions need to be mysqli
....
Thank you for help

https://myrusakov.ru/php-connect-db.html

:coffee:

firefly007 7th May 2021 10:03

Quote:

Originally Posted by budgie (Post 55469)
also this will not work on seedbox and home pc torrents On cleanups
you will get DB locks on it via mysqli it will only work on PHP 5.6 NOT 7.0 SO ON

PHP Code:

    $fields explode(":""comments:leechers:seeders");
    
$res sql_query("SELECT id, seeders, leechers, comments FROM torrents");
    while (
$row mysqli_fetch_assoc($res)) {
        
$id $row["id"];
        
$torr $torrents[$id];
        foreach (
$fields as $field) {
            if (!isset(
$torr[$field]))
                
$torr[$field] = 0;
        }
        
$update = array();
        foreach (
$fields as $field) {
            if (
$torr[$field] != $row[$field])
                
$update[] = "$field = " $torr[$field];
        }
        if (
count($update))
            
sql_query("UPDATE torrents SET " implode(","$update) . " WHERE id = $id");
    } 


If you dont already know MYSQL is deprecated in later PHP -V. As pointed out by other users in this post u need to use MYSQLI.

Good luck!

xblade 7th May 2021 10:18

i do get where u are coming from i use mysqli all the time in the code base its set to mysqli but this part not working at all well when it first uploader works ok till clean up.. as someone said above its could be the memory so on but its not nor table locking ive done my checks on this in DB to no locking at all and the memory is all good

i could add this to backend
PHP Code:

((mysqli_free_result($res1) || (is_object($res1) && (get_class($res1) == "mysqli_result"))) ? true false); 

then add to cleanup too
works ok then stop seeding its still there no good like this

firefly007 7th May 2021 10:25

I presume you have enough space on the partition? DB can lockup if there's no space Look I will have to have a look to really find what is going on.

xblade 7th May 2021 10:27

yes i do a alot of it

i was on Debian 8 was working fine seeding and all, and all then they removed it so i had to go with Debian 9 and that when it all started on cleanup.. all the code base is mysqli nps on that everything works on but that part in clean up

firefly007 7th May 2021 10:32

What source are u using? The cleanup should work out the box so I find the issue u are having very strange. Did u change something down the line?

xblade 7th May 2021 10:40

i was on Debian 8 was working fine seeding and all, and all then they removed it so i had to go with Debian 9 and that when it all started on cleanup.. all the code base is mysqli nps on that everything works on but that part in clean up
also says seeding on seedbox and home pc no errors at all just clean up sending it dead to all to see but you can download the dead torrent lol
TBDev 09
And fully working on all PHP7 7.0 7.1 7.2 so on but same probs with clean ups
--------------------------------------------------------------------------------------------
In the U-232 master its all mysqli too only probs with that is announce
on line
PHP Code:

 mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO peers (torrent, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, started, last_action, seeder, agent, downloadoffset, uploadoffset, passkey) VALUES ($torrentid{$user['id']}, ".sqlesc($peer_id).", ".sqlesc($ip).", $port, '$connectable', $uploaded$downloaded$left, ".time().", ".time().", '$seeder', ".sqlesc($agent).", $downloaded$uploaded, ".sqlesc($passkey).")") or err("PL Err 2"); 

now ive looked in to this in depth checked DB and all the inputs are there so that dose your head in when its all there in seedbox and home pc the announce errors out on this like torrent dead error PL Err 2 not telling where look in longs and server longs nothing
Also i installed on my pc still same error

firefly007 7th May 2021 11:05

Ahhh I remember getting the same error (PL Err 2) some time ago but I cant remember what i did to fix the issue. I think I did something in the announce but I could be mistaken.

Edit:

Hard to fix without actually looking at the code. If u haven't fixed the issue and I have the time I will think about installing u232

xblade 7th May 2021 11:11

IVE have been at this for months on it mate i just removed the the xampp-win32-7.0.33-0-VC14-installer
from pc and server too as the error would not fix at all not even on seedbox same error

so if you would like to give ago please do mate would love the fix for it too mate

darkalchemy 7th May 2021 20:25

Quote:

Originally Posted by budgie (Post 55469)
also this will not work on seedbox and home pc torrents On cleanups
you will get DB locks on it via mysqli it will only work on PHP 5.6 NOT 7.0 SO ON

PHP Code:

    $fields explode(":""comments:leechers:seeders");
    
$res sql_query("SELECT id, seeders, leechers, comments FROM torrents");
    while (
$row mysqli_fetch_assoc($res)) {
        
$id $row["id"];
        
$torr $torrents[$id];
        foreach (
$fields as $field) {
            if (!isset(
$torr[$field]))
                
$torr[$field] = 0;
        }
        
$update = array();
        foreach (
$fields as $field) {
            if (
$torr[$field] != $row[$field])
                
$update[] = "$field = " $torr[$field];
        }
        if (
count($update))
            
sql_query("UPDATE torrents SET " implode(","$update) . " WHERE id = $id");
    } 


Which query gives the lock? Is your table myisam or innodb?

MyISAM locks the entire table on update, InnoDB on locks the effected rows.

xblade 8th May 2021 10:16

It is the MyISAM on updates it only done it from moving from Debian 8 to Debian 9 as the server hosting removed the Debian 8

darkalchemy 8th May 2021 18:26

Quote:

Originally Posted by budgie (Post 55505)
It is the MyISAM on updates it only done it from moving from Debian 8 to Debian 9 as the server hosting removed the Debian 8

The table lock happens no matter what is you are using. The difference would be MySQL version you are using.

xblade 8th May 2021 19:01

Apache/2.4.46 (Ubuntu)
Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: 24568906d452ec590732a93b051f3827e02749b83 $
PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
PHP version: 7.0.33-0+deb9u10
Debian 9
Version information: 4.6.6deb4+deb9u2


All times are GMT +2. The time now is 04:25.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.