Last active
May 24, 2023 12:49
-
-
Save di7spider/55310df1a0367a7c82e6 to your computer and use it in GitHub Desktop.
1C Bitrix :: D7 SQL Dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Выводит / возвращает Dump SQL запроса Bitrix D7 и старого ядра */ | |
if( !function_exists('_dumpSQL') ){ | |
function _dumpSQL(callable $callback, array $params = []) | |
{ | |
$result = []; | |
if($params['user'] == 'all' || $GLOBALS['USER']-> isAdmin() ){ | |
$backtrace = array_shift( debug_backtrace() ); | |
$result['FILE'] = $backtrace['line'].": ".$backtrace['file']; | |
$con = \Bitrix\Main\Application::getConnection(); | |
$GLOBALS['DB']-> sqlTracker = $con-> startTracker(); | |
$res = call_user_func($callback); | |
$con-> stopTracker(); | |
foreach(is_array($res) ? $res : [$res] as $key => $obj){ | |
$sql = null; | |
if( is_a($obj, '\CDBResult') ){ | |
$sql = $obj-> DB-> sqlTracker-> current()-> getSql(); | |
}else if( is_a($obj, '\Bitrix\Main\DB\Result') ){ | |
$sql = $obj -> getTrackerQuery()-> getSql(); | |
} | |
if( !empty($sql) ){ | |
$result['SQL'][$key] = $sql; | |
$dump[] = $key." - ".get_class($obj)." -> \n".$sql; | |
} | |
} | |
if($params['show'] !== false){ | |
$separator = "\n".str_pad("", strlen($result['FILE']), "=")."\n"; | |
die( | |
'<pre>' | |
.$result['FILE'] | |
.$separator | |
.implode($separator, $dump) | |
.'</pre>' | |
); | |
} | |
} | |
return $result; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Пример использования:
Результат: