sql logs

UnDeaD

Новичок
Репутация
15 / 411
чуток пропатчил функу для дебага

1. засовывать куда то в начала файла, перед всеми запросами, если брать игры - файл с конектом к мускулю
2. создаем папку w0aIT_logs если лень менять скприт :D с правами на запись
Код:
$_SESSION['load_time'] = time();
$_SESSION['SQL_COUNT'] = 0;
$_SESSION['log_file'] = 'w0aIT_logs/'.date('Y.m.d[H.i.s]').'.dat';
#echo 'congif_include_ok
';
function msq($file, $line, $sql)
{
    
    if ($_SESSION['SQL_COUNT'] == 0)
    {
        fopen($_SESSION['log_file'], "w");
    }
    
    $source = file_get_contents($_SESSION['log_file']);
    $mgs_to_write_file = "===============================================\n".date('d.m.Y, G:i', time())."\n";
    $mgs_to_write_file .= $sql."\n";
    file_put_contents($_SESSION['log_file'], $source.$mgs_to_write_file);
    
    $_SESSION['SQL_COUNT']++;
    $res = @mysql_query($sql);
    if ($file[0] == "$") {echo "<pre>$sql</pre>";die();}
    #echo "
".$file;
    
    if (!$sql || mysql_error()) 
    {
        $mail = 'gmail.com';
        $headers = "Content-type: text/html; charset=windows-1251\r\n".
               "From: [email][email protected][/email]\r\n".
               "Reply-To: [email][email protected][/email]\r\n".
               "X-Mailer: PHP mailer";
        
        #$ip = getRealIpAddr();
        $subject = '['.$ip.'] MySQL ERROR';
        $body = "
        IP: $ip 

        FILE: ".$file." 
 
        LINE: ".$line." 
 
        SQL: ".$sql." 

        ______________________________________________

        ".mysql_error();
        #mail($mail, $subject, $body, $headers);
        echo $body;
        die('tech error');
    }
    else 
    return $res;
}

после этого делаем автозамену
mysql_query( на msq(__FILE__,__LINE__,


в результате получаем подобный лог

Код:
===============================================
06.02.2010, 8:23

        select
            person.id, 
            person.user,
            person.rank,
            person.level,
            person.strength,
            person.dex,
            person.agility,
            person.vitality,
            person.power,
            person.razum,
            person.tribe,
            person.battle,
            person.obraz,
            person.sex,
            person.credits,
            person.elik_time,
            person.elik_action,
            person.invisible,
            participants.hp as hp_now,
            participants.hp_max,
            participants.id as part_id,
            participants.char_type,
            participants.side,
            participants.current_enemy,
            participants.user_hide
        from 
            person,
            participants
        where 
            person.user='UnDeaD' 
                and 
            person.pass='' 
                AND
            participants.user = person.user
                AND
            participants.battle_id = person.battle
        LIMIT 1

===============================================
06.02.2010, 8:23
SELECT * FROM offers WHERE time = 2 
===============================================
06.02.2010, 8:23

    SELECT 
        hp as hp_now, 
        hp_max, 
        current_enemy,
        side,
        damage,
        changes
    FROM 
        participants
    WHERE
        user = 'UnDeaD' AND
        battle_id = 2

===============================================
06.02.2010, 8:23
SELECT count(*) FROM participants WHERE battle_id=2 AND side = 0 AND hp > 0 
===============================================
06.02.2010, 8:23
SELECT count(*) FROM participants WHERE battle_id=2 AND side = 1 AND hp > 0 
===============================================
06.02.2010, 8:23
SELECT * FROM person_changed WHERE person = 'UnDeaD' 
===============================================
06.02.2010, 8:23
SELECT count(b_id) FROM battles_hit WHERE battle_id=2 AND attacker = 'UnDeaD' 
===============================================
06.02.2010, 8:23
SELECT count(*) FROM battles_hit WHERE defender = 'UnDeaD' AND time > 1265437390 AND battle_id = 2 
===============================================
06.02.2010, 8:23
SELECT hp FROM participants WHERE user = 'UnDeaD' AND battle_id=2 
===============================================
06.02.2010, 8:23

    SELECT 
        * 
    FROM 
        battles_stat 
    WHERE 
        u_id = 1

===============================================
06.02.2010, 8:23

        SELECT
            *
        FROM
            priemy_slots
        WHERE
            user_id = 1
    
===============================================
06.02.2010, 8:23

    SELECT
        *
    FROM
        participants
    WHERE
        battle_id = 2
            AND
        hp > 0
    ORDER by side ASC

===============================================
06.02.2010, 8:23
SELECT p_id FROM battles_priems_used WHERE battle_id = 2 and user = 'UnDeaD' 
===============================================
06.02.2010, 8:23

    SELECT 
        count(*) 
    FROM 
        battles_hit
    WHERE 
        battles_hit.battle_id= 2 AND 
        battles_hit.attacker = 'UnDeaD' AND 
        battles_hit.defender = 'UnDeaD (клон 1)'
    LIMIT 1

===============================================
06.02.2010, 8:23

    SELECT
        count(*) 
    FROM
        participants
    WHERE
        participants.hp > 0 AND
        participants.user = 'UnDeaD (клон 1)' AND
        participants.battle_id = 2
    LIMIT 1

===============================================
06.02.2010, 8:23
 SELECT hp_max, char_type FROM participants WHERE user = 'UnDeaD (клон 1)' and battle_id = 2 
===============================================
06.02.2010, 8:23

    SELECT
        person_clon.id, 
        person_clon.rank,
        person_clon.level,
        person_clon.obraz,
        person_clon.sex,
        person_clon.tribe,
        person_clon.invisible,
        person_clon.energy_now,
        participants.hp as hp_now,
        participants.hp_max,
        participants.id as part_id,
        participants.user as user,
        participants.char_type,
        participants.side,
        participants.current_enemy,
        participants.user_hide
    FROM
        person_clon,
        participants
    WHERE
        person_clon.user = 'UnDeaD (клон 1)'
            AND
        participants.user = person_clon.user
            AND
        participants.battle_id = 2

===============================================
06.02.2010, 8:23
SELECT * FROM person_changed WHERE person = 'UnDeaD (клон 1)' 
===============================================
06.02.2010, 8:23
UPDATE participants SET current_enemy = 'UnDeaD (клон 1)' WHERE user = 'UnDeaD' and battle_id    = 2 
===============================================
06.02.2010, 8:23
SELECT objects.* FROM slots, objects WHERE slots.id='1' AND objects.user='UnDeaD' AND 
                (objects.id=slots.1 OR objects.id=slots.2 OR objects.id=slots.3 OR objects.id=slots.4
                        OR objects.id=slots.5 OR objects.id=slots.6 OR objects.id=slots.7
                        OR objects.id=slots.8 OR objects.id=slots.9
                        OR objects.id=slots.10 OR objects.id=slots.11
                        OR objects.id=slots.12 OR objects.id=slots.13
                        OR objects.id=slots.14 OR objects.id=slots.15
                        OR objects.id=slots.16 OR objects.id=slots.17
                        OR objects.id=slots.18 OR objects.id=slots.19
                        OR objects.id=slots.20 OR objects.id=slots.21
                        OR objects.id=slots.22) AND onset > 0 ORDER by onset ASC
===============================================
06.02.2010, 8:23

    select
        person.id, 
        person.user,
        person.rank,
        person.level,
        person.strength,
        person.dex,
        person.agility,
        person.vitality,
        person.power,
        person.razum,
        person.tribe,
        person.battle,
        person.side,
        person.credits,
        person.elik_time,
        person.elik_action,
        participants.hp as hp_now,
        participants.hp_max,
        participants.id as part_id,
        participants.char_type,
        participants.side,
        participants.current_enemy
    from 
        person,
        participants
    where 
        person.last_hit < 1265377391    AND
        person.battle = 2 AND
        participants.char_type = 1 AND
        participants.user != 'UnDeaD'
            AND
        participants.user = person.user
            AND
        participants.battle_id = person.battle

ахуенно удобная шняга для просмотра того что ты написдохал в коде и что из запросов лишнее
 
Сверху