<?php
require_once(PLUGIN_DIR . 'lib/php4log/Logger.php');

class DBManager {
    public static function query($sql){
        global $wpdb;
        $result = $wpdb->query($sql);
        print_r($result->last_query);
        DBManager::getLog()->info($wpdb->last_query);
        if($result->last_error){
            DBManager::getLog()->error($wpdb->last_error);
            return $result->last_error;
        }
        return $result;
    }

    public static function get_results($sql){
        global $wpdb;
        $result = $wpdb->get_results($sql);
        DBManager::getLog()->info($wpdb->last_query);
        if($result->last_error){
            DBManager::getLog()->error($wpdb->last_error);
            return $result->last_error;
        }
        return $result;
    }

    public static function getLog(){
        $config = PLUGIN_DIR . 'appender_pdo.properties';
        $logger = Logger::configure($config);
        $log = Logger::getLogger('log');
        return $log;
    }

} 