<commit_before><?php

class MySQLConn {
	private static $_instance = null;
	private $_pdo, $_conn;
	private $_error = false, $_count = 0, $_lastID;


	/**
	* Setup connection
	*/
	private function __construct() {
		$dsn = "mysql:host=".Config::get('db_host');
		$dsn .= ";dbname=".Config::get('db_name');
		$dsn .= ";charset=".Config::get('db_charset');
		$username = Config::get('db_username');
		$password = Config::get('db_password');

		$opt = [
		    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
		    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
		    //PDO::ATTR_EMULATE_PREPARES   => false
		];

		// TODO: need a better error handler if unable to establish connection
		try {
			$this->_pdo = new PDO($dsn, $username, $password, $opt);
		}
		catch(PDOException $e) {
			// display friendly message here instead
			// log exception in a log file
			die($e->getMessage());
		}
	}


	/**
	* Return an instance of this object
	*
	* @return MySQLConn                  Instance of MySQLConn
	*/
	public static function getInstance() {
		if(!isset(self::$_instance)) {
			self::$_instance = new MySQLConn();
		}

		return self::$_instance;
	}


	/**<commit_msg>Enabled persistent connection for PDO<commit_after><?php

class MySQLConn {
	private static $_instance = null;
	private $_pdo, $_conn;
	private $_error = false, $_count = 0, $_lastID;


	/**
	* Setup connection
	*/
	private function __construct() {
		$dsn = "mysql:host=".Config::get('db_host');
		$dsn .= ";dbname=".Config::get('db_name');
		$dsn .= ";charset=".Config::get('db_charset');
		$username = Config::get('db_username');
		$password = Config::get('db_password');

		$opt = [
		    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
		    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
		    PDO::ATTR_PERSISTENT => true
		    //PDO::ATTR_EMULATE_PREPARES   => false
		];

		// TODO: need a better error handler if unable to establish connection
		try {
			$this->_pdo = new PDO($dsn, $username, $password, $opt);
		}
		catch(PDOException $e) {
			// display friendly message here instead
			// log exception in a log file
			die($e->getMessage());
		}
	}


	/**
	* Return an instance of this object
	*
	* @return MySQLConn                  Instance of MySQLConn
	*/
	public static function getInstance() {
		if(!isset(self::$_instance)) {
			self::$_instance = new MySQLConn();
		}

		return self::$_instance;
	}


	/**
{'fraction_non_alphanumeric': 0.15935430463576158, 'fraction_numerical': 0.0008278145695364238, 'mean_word_length': 3.3945454545454545, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '1520202', 'n_tokens_mistral': 904, 'n_tokens_neox': 795, 'n_words': 188}