<commit_before><?php

namespace Medoo;

use \PDO;

/*!
 * Medoo database framework
 * http://medoo.in
 * Version 1.1.3
 *
 * Copyright 2016, <NAME>
 * Released under the MIT license
 */
class Medoo
{
	// General
	protected $database_type;

	protected $charset;

	protected $database_name;

	// For MySQL, MariaDB, MSSQL, Sybase, PostgreSQL, Oracle
	protected $server;

	protected $username;

	protected $password;

	// For SQLite
	protected $database_file;

	// For MySQL or MariaDB with unix_socket
	protected $socket;

	// Optional
	protected $port;

	protected $prefix;

	protected $option = array();

	// Variable
	protected $logs = array();

	protected $debug_mode = false;

	public function __construct($options = null, $externalPDO = null)
	{
		if(isset($externalPDO)) {
			$this->pdo = $externalPDO;
		} else {
			try {
				$commands = array();
				$dsn = '';

				if (is_array($options))
				{
					foreach ($options as $option => $value)
					{
						$this->$option = $value;
					}
				}
				else
				{
					return false;
				}

				if (
					isset($this->port) &&
					is_int($this->port * 1)
				)
				{
					$port = $this->port;
				}

				$type = strtolower($this->database_type);
				$is_port = isset($port);

				if (isset($options[ 'prefix' ]))
				{
					$this->prefix = $options[ 'prefix' ];
				}

				switch ($type)
				{
					case 'mariadb':
						$type = 'mysql';

					case 'mysql':
						if ($this->socket)
						{
							$dsn = $type . ':unix_socket=' . $this->socket . ';dbname=' . $this->database_name;
						}
						else
						{
							$dsn = $type . ':host=' . $this->server . ($is_port ? ';port=' . $port : '') . ';dbname=' . $this->database_name;
						}

						// Make MySQL using standard quoted identifier
						$commands[] = 'SET SQL_MODE=ANSI_QUOTES';
						break;

					case 'pgsql':
						$dsn = $type . ':host=' . $this->server . ($is_port ? ';port=' . $port : '') . ';dbname=' . $this->database_name;
						break;

					case 'sybase':
						$dsn = 'dblib:host=' . $this->server . ($is_port ? ':' . $port : '') . ';dbname=' . $this->database_name;
						break;

					case 'oracle':
						$dbname = $this->server ?
							'//' . $this->server . ($is_port ? ':' . $port : ':1521') . '/' . $this->database_name :
							$this->database_name;

						$dsn = 'oci:dbname=' . $dbname . ($this->charset ? ';charset=' . $this->charset : '');
						break;

					case 'mssql':
						$dsn = strstr(PHP_OS, 'WIN') ?
							'sqlsrv:server=' . $this->server . ($is_port ? ',' . $port : '') . ';database=' . $this->database_name :
							'dblib:host=' . $this->server . ($is_port ? ':' . $port : '') . ';dbname=' . $this->database_name;

						// Keep MSSQL QUOTED_IDENTIFIER is ON for standard quoting
						$commands[] = 'SET QUOTED_IDENTIFIER ON';
						break;

					case 'sqlite':
						$dsn = $type . ':' . $this->database_file;
						$this->username = null;
						$this->password = <PASSWORD>;
						break;
				}

				if (
					in_array($type, array('mariadb', 'mysql', 'pgsql', 'sybase', 'mssql')) &&
					$this->charset
				)
				{
					$commands[] = "SET NAMES '" . $this->charset . "'";
				}

				$this->pdo = new PDO(
					$dsn,
					$this->username,
					$this->password,
					$this->option
				);

				foreach ($commands as $value)
				{
					$this->pdo->exec($value);
				}
			}
			catch (PDOException $e) {
				throw new Exception($e->getMessage());
			}
		}
	}

	public function query($query)
	{
		if ($this->debug_mode)
		{
			echo $query;

			$this->debug_mode = false;

			return false;
		}

		$this->logs[] = $query;

		return $this->pdo->query($query);
	}

	public function exec($query)
	{
		if ($this->debug_mode)
		{
			echo $query;

			$this->debug_mode = false;

			return false;
		}

		$this->logs[] = $query;

		return $this->pdo->exec($query);
	}

	public function quote($string)
	{
		return $this->pdo->quote($string);
	}

	protected function table_quote($table)
	{
		return '`' . $this->prefix . $table . '`';<commit_msg>Supporting Monolog<commit_after><?php

namespace Medoo;

use \PDO;

/*!
 * Medoo database framework
 * http://medoo.in
 * Version 1.1.3
 *
 * Copyright 2016, <NAME>
 * Released under the MIT license
 */
class Medoo
{
	// General
	protected $database_type;

	protected $charset;

	protected $database_name;

	// For MySQL, MariaDB, MSSQL, Sybase, PostgreSQL, Oracle
	protected $server;

	protected $username;

	protected $password;

	// For SQLite
	protected $database_file;

	// For MySQL or MariaDB with unix_socket
	protected $socket;

	// Optional
	protected $port;

	protected $prefix;

	protected $option = array();

	// Variable
	protected $logs = array();

	protected $debug_mode = false;

	public function __construct($options = null, $externalPDO = null, $logger = null)
	{
		if (isset($logger)) {
			$this->logger = $logger;
		}

		if(isset($externalPDO)) {
			$this->pdo = $externalPDO;
		} else {
			try {
				$commands = array();
				$dsn = '';

				if (is_array($options))
				{
					foreach ($options as $option => $value)
					{
						$this->$option = $value;
					}
				}
				else
				{
					return false;
				}

				if (
					isset($this->port) &&
					is_int($this->port * 1)
				)
				{
					$port = $this->port;
				}

				$type = strtolower($this->database_type);
				$is_port = isset($port);

				if (isset($options[ 'prefix' ]))
				{
					$this->prefix = $options[ 'prefix' ];
				}

				switch ($type)
				{
					case 'mariadb':
						$type = 'mysql';

					case 'mysql':
						if ($this->socket)
						{
							$dsn = $type . ':unix_socket=' . $this->socket . ';dbname=' . $this->database_name;
						}
						else
						{
							$dsn = $type . ':host=' . $this->server . ($is_port ? ';port=' . $port : '') . ';dbname=' . $this->database_name;
						}

						// Make MySQL using standard quoted identifier
						$commands[] = 'SET SQL_MODE=ANSI_QUOTES';
						break;

					case 'pgsql':
						$dsn = $type . ':host=' . $this->server . ($is_port ? ';port=' . $port : '') . ';dbname=' . $this->database_name;
						break;

					case 'sybase':
						$dsn = 'dblib:host=' . $this->server . ($is_port ? ':' . $port : '') . ';dbname=' . $this->database_name;
						break;

					case 'oracle':
						$dbname = $this->server ?
							'//' . $this->server . ($is_port ? ':' . $port : ':1521') . '/' . $this->database_name :
							$this->database_name;

						$dsn = 'oci:dbname=' . $dbname . ($this->charset ? ';charset=' . $this->charset : '');
						break;

					case 'mssql':
						$dsn = strstr(PHP_OS, 'WIN') ?
							'sqlsrv:server=' . $this->server . ($is_port ? ',' . $port : '') . ';database=' . $this->database_name :
							'dblib:host=' . $this->server . ($is_port ? ':' . $port : '') . ';dbname=' . $this->database_name;

						// Keep MSSQL QUOTED_IDENTIFIER is ON for standard quoting
						$commands[] = 'SET QUOTED_IDENTIFIER ON';
						break;

					case 'sqlite':
						$dsn = $type . ':' . $this->database_file;
						$this->username = null;
						$this->password = <PASSWORD>;
						break;
				}

				if (
					in_array($type, array('mariadb', 'mysql', 'pgsql', 'sybase', 'mssql')) &&
					$this->charset
				)
				{
					$commands[] = "SET NAMES '" . $this->charset . "'";
				}

				$this->pdo = new PDO(
					$dsn,
					$this->username,
					$this->password,
					$this->option
				);

				foreach ($commands as $value)
				{
					$this->pdo->exec($value);
				}
			}
			catch (\Exception $e) {
				throw new \Exception($e->getMessage());
			}
		}
	}

	public function query($query)
	{
		if ($this->debug_mode)
		{
			echo $query;

			$this->debug_mode = false;

			return false;
		}

		$this->logs[] = $query;

		try {
			return $this->pdo->query($query);
		} catch (\Exception $e) {

			if ($this->logger != null) {
				$this->logger->error('MySQL error: '.$query);
			}
		}
	}

	public function exec($query)
	{
		if ($this->debug_mode)
		{
			echo $query;

			$this->debug_mode = false;

			return false;
		}

		$this->logs[] = $query;

		try {
			return $this->pdo->exec($query);
		} catch (\Exception $e) {

			if ($this->logger != null) {
				$this->logger->error('MySQL error: '.$query);
			}
		}

	}

	public function quote($string)
	{
		return $this->pdo->quote($string);
	}

	protected function table_quote($table)
	{
		return '`' . $this->prefix . $table . '`';
{'fraction_non_alphanumeric': 0.190832328106152, 'fraction_numerical': 0.0028950542822677927, 'mean_word_length': 2.35668016194332, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 118, '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': '6011310', 'n_tokens_mistral': 3884, 'n_tokens_neox': 2950, 'n_words': 619}