<commit_before><?php
/**
 * Kontiki\Db
 *
 * @package    part of Kontiki
 * @version    1.0
 * @author     Jidaikobo Inc.
 * @license    WTFPL2.0
 * @copyright  Jidaikobo Inc.
 * @link       http:/www.jidaikobo.com
 */
namespace Kontiki;
class Db
{
	protected $dbh;
	protected $name;
	protected $dbtype;
	protected static $_instances = array();

	/**
	 * instance
	 *
	 * @param   string    $name
	 * @return  instance
	 */
	public static function instance($name = 'default')
	{
		return array_key_exists($name, static::$_instances) ? static::$_instances[$name] : FALSE;
	}

	/**
	 * Create Db object
	 *
	 * @param   string    Identifier for this db
	 * @param   array     Configuration array
	 * @return  Fieldset
	 */
	public static function forge($name = 'default', $cons = array())
	{
		// config
		if (is_array($name))
		{
			$cons = $name;
			$name = 'default';
		}

		// exists
		if (static::instance($name)) die('already exists');

		// instance
		static::$_instances[$name] = new static($name, $cons);
	}

	/**
	 * __construct
	 *
	 * @return  void
	 */
	public function __construct($name, $config)
	{
		$dbtype = strtolower($config['dbtype']);
		// sqlite
		if ($dbtype == 'sqlite')
		{
			try
			{
				$dbh = new \PDO("sqlite:".$config['path']);
				$dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
			}
			catch (\PDOException $e)
			{
				die ('Connection failed : '.$e->getMessage());
			}
		}
		// mysql
		elseif ($dbtype == 'mysql')
		{
			$dtbs = 'mysql:dbname='.$config['db'].';host='.$config['host'];
			try
			{
				$dbh = new \PDO($dtbs, $config['user'], $config['password']);
			}
			catch (\PDOException $e)
			{
				die('Error:'.$e->getMessage());
			}
			$dbh->query('SET NAMES UTF8;');
		}

		$this->dbtype = $dbtype;
		$this->dbh = $dbh;
	}

	/*
	 * init table
	 *
	 * @param   string  $name
	 * @return  void
	 */
	public static function init_table($name = 'default')
	{<commit_msg>set default encoding at PDO<commit_after><?php
/**
 * Kontiki\Db
 *
 * @package    part of Kontiki
 * @version    1.0
 * @author     Jidaikobo Inc.
 * @license    WTFPL2.0
 * @copyright  Jidaikobo Inc.
 * @link       http:/www.jidaikobo.com
 */
namespace Kontiki;
class Db
{
	protected $dbh;
	protected $name;
	protected $dbtype;
	protected static $_instances = array();

	/**
	 * instance
	 *
	 * @param   string    $name
	 * @return  instance
	 */
	public static function instance($name = 'default')
	{
		return array_key_exists($name, static::$_instances) ? static::$_instances[$name] : FALSE;
	}

	/**
	 * Create Db object
	 *
	 * @param   string    Identifier for this db
	 * @param   array     Configuration array
	 * @return  Fieldset
	 */
	public static function forge($name = 'default', $cons = array())
	{
		// config
		if (is_array($name))
		{
			$cons = $name;
			$name = 'default';
		}

		// exists
		if (static::instance($name)) die('already exists');

		// instance
		static::$_instances[$name] = new static($name, $cons);
	}

	/**
	 * __construct
	 *
	 * @return  void
	 */
	public function __construct($name, $config)
	{
		$dbtype = strtolower($config['dbtype']);
		// sqlite
		if ($dbtype == 'sqlite')
		{
			try
			{
				$dbh = new \PDO("sqlite:".$config['path'].';charset=utf8');
				$dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
			}
			catch (\PDOException $e)
			{
				die ('Connection failed : '.$e->getMessage());
			}
		}
		// mysql
		elseif ($dbtype == 'mysql')
		{
			$dtbs = 'mysql:dbname='.$config['db'].';charset=utf8;host='.$config['host'];
			try
			{
				$dbh = new \PDO($dtbs, $config['user'], $config['password']);
			}
			catch (\PDOException $e)
			{
				die('Error:'.$e->getMessage());
			}
			$dbh->query('SET NAMES UTF8;');
		}

		$this->dbtype = $dbtype;
		$this->dbh = $dbh;
	}

	/*
	 * init table
	 *
	 * @param   string  $name
	 * @return  void
	 */
	public static function init_table($name = 'default')
	{
{'fraction_non_alphanumeric': 0.1829612522453169, 'fraction_numerical': 0.003079291762894534, 'mean_word_length': 2.8824701195219125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6858373', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1396, 'n_words': 300}