<?php
if (!function_exists('wr_db_guard_normalize')) {
    function wr_db_guard_normalize(){
        global $db,$conn;
        if((!isset($conn) || !($conn instanceof mysqli)) && isset($db) && $db instanceof mysqli) $conn=$db;
        if((!isset($db) || !($db instanceof mysqli)) && isset($conn) && $conn instanceof mysqli) $db=$conn;
        if(!isset($conn) || !($conn instanceof mysqli)){ wr_runtime_log('SQL','DB connection object not found',array(),__FILE__,__LINE__); return false; }
        if($conn->connect_errno){ wr_runtime_log('SQL','DB connection failed',array('errno'=>$conn->connect_errno,'error'=>$conn->connect_error),__FILE__,__LINE__); return false; }
        if(!@$conn->set_charset('utf8mb4')) wr_runtime_log('SQL','Unable to set utf8mb4',array('errno'=>$conn->errno,'error'=>$conn->error),__FILE__,__LINE__);
        return true;
    }
}
if (!function_exists('wr_db_guard_ping')) { function wr_db_guard_ping(){ global $conn; return isset($conn)&&$conn instanceof mysqli&&@$conn->ping(); } }
