<commit_before><?php
/**
 * Shows information about current MySQL connection
 */

//TODO: present data in pretty tables
//TODO: use pie charts to show percentage of used memory etc

$session->requireSuperAdmin();

echo '<h1>Default MySQL db information</h1>';
echo 'Driver: '.get_class($db).'<br/>';
echo 'Server version: <b>'.$db->db_handle->server_info.'</b><br/>';
echo 'Client version: <b>'.$db->db_handle->client_info.'</b><br/>';
echo 'Host: <b>'.$db->host.':'.$db->port.'</b><br/>';
echo 'Username: <b>'.$db->username.'</b><br/>';
// echo 'Password: '.($db->password ? $db->password : '(blank)').'<br/>';
echo 'Database: '.$db->database.'<br/>';
echo 'Configured charset: '.$db->charset.'<br/>';
echo '<br/>';

echo '<h2>Database time</h2>';
$db_time = $db->getOneItem('SELECT NOW()');
echo 'Database time: '.$db_time.'<br/>';
echo 'Webserver time: '.now().'<br/>';

$uptime = $db->getOneRow('SHOW STATUS WHERE Variable_name="Uptime"');
echo 'Database uptime: '.elapsed_seconds($uptime['Value']).'<br/>';

echo '<br/>';

echo '<h2>Driver specific settings</h2>';
echo 'Host info: '.$db->db_handle->host_info.'<br/>';
echo 'Connection character set: '.$db->db_handle->character_set_name().'<br/>';
echo 'Last error: '.$db->db_handle->error.'<br/>';
echo 'Last errno: '.$db->db_handle->errno.'<br/>';
echo '<br/>';

// show MySQL query cache settings
$data = $db->getMappedArray('SHOW VARIABLES LIKE "%query_cache%"');
if ($data['have_query_cache'] == 'YES') {
    echo '<h2>MySQL query cache settings</h2>';
    echo 'Type: '. $data['query_cache_type'].'<br/>';        //valid values: ON, OFF or DEMAND
    echo 'Size: '. formatDataSize($data['query_cache_size']).' (total size)<br/>';
    echo 'Limit: '. formatDataSize($data['query_cache_limit']).' (per query)<br/>';
    echo 'Min result unit: '. formatDataSize($data['query_cache_min_res_unit']).'<br/>';
    echo 'Wlock invalidate: '. $data['query_cache_wlock_invalidate'].'<br/><br/>';

    // current query cache status
    $data = $db->getMappedArray('SHOW STATUS LIKE "%Qcache%"', 'Variable_name', 'Value');
    echo '<h2>MySQL query cache status</h2>';
    echo 'Hits: '. formatNumber($data['Qcache_hits']).'<br/>';
    echo 'Inserts: '. formatNumber($data['Qcache_inserts']).'<br/>';
    echo 'Queries in cache: '. formatNumber($data['Qcache_queries_in_cache']).'<br/>';
    echo 'Total blocks: '. formatNumber($data['Qcache_total_blocks']).'<br/>';
    echo '<br/>';
    echo 'Not cached: '. formatNumber($data['Qcache_not_cached']).'<br/>';
    echo 'Free memory: '. formatDataSize($data['Qcache_free_memory']).'<br/>';
    echo '<br/>';
    echo 'Free blocks: '. formatNumber($data['Qcache_free_blocks']).'<br/>';
    echo 'Lowmem prunes: '. formatNumber($data['Qcache_lowmem_prunes']);
} else {
    echo '<h2>MySQL query cache is disabled</h2>';
}

?><commit_msg>* show current user privilegies * use prepared statements<commit_after><?php
/**
 * Shows information about current MySQL connection
 */

//TODO: present data in pretty tables
//TODO: use pie charts to show percentage of used memory etc

$session->requireSuperAdmin();

echo '<h1>Default MySQL db information</h1>';
echo 'Driver: '.get_class($db).'<br/>';
echo 'Server version: <b>'.$db->db_handle->server_info.'</b><br/>';
echo 'Client version: <b>'.$db->db_handle->client_info.'</b><br/>';
echo 'Host: <b>'.$db->host.':'.$db->port.'</b><br/>';
echo 'Username: <b>'.$db->username.'</b><br/>';
// echo 'Password: '.($db->password ? $db->password : '(blank)').'<br/>';
echo 'Database: '.$db->database.'<br/>';
echo 'Configured charset: '.$db->charset.'<br/>';



$q = 'SHOW GRANTS FOR CURRENT_USER';
$priv = Sql::pSelectItem($q);
//XXXX: parse output and complain if too low or too high priviliegies!
// example:  GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD <PASSWORD>'
// example2: GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD <PASSWORD>' WITH GRANT OPTION
echo 'Privilegies: <b>'.substr($priv, 0, 70).'</b>...<br/>';
echo'<br/>';



echo '<h2>Database time</h2>';
$db_time = Sql::pSelectItem('SELECT NOW()');
echo 'Database time: '.$db_time.'<br/>';
echo 'Webserver time: '.now().'<br/>';

$uptime = Sql::pSelectRow('SHOW STATUS WHERE Variable_name = ?', 's', 'Uptime');
echo 'Database uptime: '.elapsed_seconds($uptime['Value']).'<br/>';

echo '<br/>';

echo '<h2>Driver specific settings</h2>';
echo 'Host info: '.$db->db_handle->host_info.'<br/>';
echo 'Connection character set: '.$db->db_handle->character_set_name().'<br/>';
echo 'Last error: '.$db->db_handle->error.'<br/>';
echo 'Last errno: '.$db->db_handle->errno.'<br/>';
echo '<br/>';

// show MySQL query cache settings

$data = Sql::pSelectMapped('SHOW VARIABLES LIKE "%query_cache%"');

if ($data['have_query_cache'] == 'YES')
{
    echo '<h2>MySQL query cache settings</h2>';
    echo 'Type: '. $data['query_cache_type'].'<br/>';        //valid values: ON, OFF or DEMAND
    echo 'Size: '. formatDataSize($data['query_cache_size']).' (total size)<br/>';
    echo 'Limit: '. formatDataSize($data['query_cache_limit']).' (per query)<br/>';
    echo 'Min result unit: '. formatDataSize($data['query_cache_min_res_unit']).'<br/>';
    echo 'Wlock invalidate: '. $data['query_cache_wlock_invalidate'].'<br/><br/>';

    // current query cache status
    $data = Sql::pSelectMapped('SHOW STATUS LIKE "%Qcache%"');

    echo '<h2>MySQL query cache status</h2>';
    echo 'Hits: '. formatNumber($data['Qcache_hits']).'<br/>';
    echo 'Inserts: '. formatNumber($data['Qcache_inserts']).'<br/>';
    echo 'Queries in cache: '. formatNumber($data['Qcache_queries_in_cache']).'<br/>';
    echo 'Total blocks: '. formatNumber($data['Qcache_total_blocks']).'<br/>';
    echo '<br/>';
    echo 'Not cached: '. formatNumber($data['Qcache_not_cached']).'<br/>';
    echo 'Free memory: '. formatDataSize($data['Qcache_free_memory']).'<br/>';
    echo '<br/>';
    echo 'Free blocks: '. formatNumber($data['Qcache_free_blocks']).'<br/>';
    echo 'Lowmem prunes: '. formatNumber($data['Qcache_lowmem_prunes']);
}
else
{
    echo '<h2>MySQL query cache is disabled</h2>';
}

?>
{'fraction_non_alphanumeric': 0.2338486574450773, 'fraction_numerical': 0.004556550040683482, 'mean_word_length': 4.8533333333333335, 'pattern_counts': {'":': 0, '<': 116, '<?xml version=': 0, '>': 160, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3821076', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2175, 'n_words': 486}