Made mysql connection and charset setting errors more graceful; added “users” page to updstats; other minor changes

This commit is contained in:
pezcurrel 2022-12-17 17:35:35 +01:00
parent 2d1d28b002
commit ad8fa26306

View file

@ -101,10 +101,14 @@ function mexit($msg,$code) {
$inifp=__DIR__.'/../conf/mustard.ini';
$iniarr=@parse_ini_file($inifp)
or mexit('Could not open configuration file «'.$inifp.'»'.N,1);
$link=@mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket'])
or mexit('Could not connect to MySQL server: '.mysqli_connect_error().N,1);
mysqli_set_charset($link,'utf8mb4')
or mexit('Could not set MySQL connection charset to «utf8mb4»: '.mysqli_error($link).N,1);
try { $link=@mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket']); }
catch (Exception $error) { mexit('could not connect to MySQL server: '.mysqli_connect_error().'.'.N,1,true); }
// for php versions < 8
if ($link===false) mexit('could not connect to MySQL server: '.mysqli_connect_error().'.'.N,1,true);
try { $res=mysqli_set_charset($link,'utf8mb4'); }
catch (Exception $error) { mexit('could not set «utf8mb4» charset for MySQL: '.mysqli_error($link).'.'.N,1,true); }
// for php versions < 8
if ($res===false) mexit('could not set MySQL charset: '.mysqli_errno($link).': '.mysqli_error($link).'.'.N,1,true);
/*if ($opts['setold']) {
echo('Setting «New=0» for instances which are no longer new ... ');
@ -165,7 +169,7 @@ if ($opts['updstats']) {
// this line below must be synced with $supplangs in ../site/index.php
$hitslang=array('ca'=>0, 'de'=>0, 'en'=>0, 'es'=>0, 'fr'=>0, 'gl'=>0, 'it'=>0, 'pt_BR'=>0, 'uk'=>0);
// this line below must be synced with the urls we consider, see ../site/index.php
$hitspage=array('home'=>0, 'instances'=>0, 'about'=>0, 'stats'=>0, 'contribute'=>0, '404'=>0);
$hitspage=array('home'=>0, 'instances'=>0, 'users'=>0, 'about'=>0, 'stats'=>0, 'contribute'=>0, '404'=>0);
$visits=0;
$buf=array();
$res=mysqli_query($link,'SELECT * FROM ZHits WHERE TS >= '.$dstart.' AND TS < '.($dstart+$day).' ORDER BY TS ASC') or mexit(__LINE__.': '.mysqli_error($link).N,2);
@ -199,13 +203,13 @@ if ($opts['clean']) {
$ago=time()-($opts['clean_before_weeks']*7*24*60*60);
echo('Cleaning records older than '.$opts['clean_before_weeks'].' weeks from «Notifications» table...'.N);
$res=mysqli_query($link,'DELETE FROM Notifications WHERE Microtime < '.$ago) or mexit(__LINE__.': '.mysqli_error($link).N,2);
echo('Done! Affected rows:: '.mysqli_affected_rows($link).'.'.N);
echo('Done! Affected rows: '.mysqli_affected_rows($link).'.'.N);
}
if ($opts['resurrect']) {
echo('Setting «Dead=0» for records with «Dead!=0»...'.N);
$res=mysqli_query($link,'UPDATE Instances SET Dead=0 WHERE Dead!=0') or mexit(__LINE__.': '.mysqli_error($link).N,2);
echo('Done! Affected rows:: '.mysqli_affected_rows($link).'.'.N);
echo('Done! Affected rows: '.mysqli_affected_rows($link).'.'.N);
}
if ($opts['optimize']) {