<commit_before><?php

/*
 * This file is part of the Storage package
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Moss\Storage\Driver;

/**
 * PDO implementing driver interface
 *
 * @author  <NAME> <<EMAIL>>
 * @package Moss\Storage\Driver
 */
class PDO implements DriverInterface
{

    protected $prefix;

    /** @var \PDO */
    protected $pdo;

    /** @var \PDOStatement */
    protected $statement;

    /**
     * Constructor
     *
     * @param string $driver
     * @param string $database
     * @param string $username
     * @param string $password
     * @param string $hostname
     * @param int    $port
     * @param string $prefix
     *
     * @throws DriverException
     */
    public function __construct($driver, $database, $username, $password, $hostname = 'localhost', $port = 3306, $prefix = null)
    {
        $initCmd = array(
            \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
            \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
            \PDO::ATTR_EMULATE_PREPARES => 1,
        );

        $dsn = sprintf('%s:dbname=%s;host=%s;port=%u', $driver, $database, $hostname, $port);
        if (!$this->pdo = new \PDO($dsn, $username, $password, $initCmd)) {
            throw new DriverException('Database adapter error!');
        }

        if (!empty($prefix)) {
            $this->prefix = $prefix . '_';
        }

        if ($this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql') {
            $encoding = ($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION) >= 5.5) ? 'utf8mb4' : 'utf8';

            $this->pdo->setAttribute(\PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES ' . $encoding); // re-connect
            $this->pdo->exec(' SET NAMES ' . $encoding); // current
        }
    }

    /**
     * Destructor
     */
    public function __destruct()
    {
        $this->pdo = null;
    }

    /**
     * Returns current statements query string
     *
     * @return string
     */<commit_msg>changed constructor<commit_after><?php

/*
 * This file is part of the Storage package
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Moss\Storage\Driver;

/**
 * PDO implementing driver interface
 *
 * @author  <NAME> <<EMAIL>>
 * @package Moss\Storage\Driver
 */
class PDO implements DriverInterface
{

    protected $prefix;

    /** @var \PDO */
    protected $pdo;

    /** @var \PDOStatement */
    protected $statement;

    /**
     * Constructor
     *
     * @param string $dsn
     * @param string $username
     * @param string $password
     * @param string $prefix
     *
     * @throws DriverException
     */
    public function __construct($dsn, $username, $password, $prefix = null)
    {
        $initCmd = array(
            \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
            \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
            \PDO::ATTR_EMULATE_PREPARES => 1,
        );

        if (!$this->pdo = new \PDO($dsn, $username, $password, $initCmd)) {
            throw new DriverException('Database adapter error!');
        }

        if (!empty($prefix)) {
            $this->prefix = $prefix . '_';
        }

        if ($this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql') {
            $encoding = ($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION) >= 5.5) ? 'utf8mb4' : 'utf8';

            $this->pdo->setAttribute(\PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES ' . $encoding); // re-connect
            $this->pdo->exec(' SET NAMES ' . $encoding); // current
        }
    }

    /**
     * Destructor
     */
    public function __destruct()
    {
        $this->pdo = null;
    }

    /**
     * Returns current statements query string
     *
     * @return string
     */
{'fraction_non_alphanumeric': 0.1493522987045974, 'fraction_numerical': 0.004064008128016256, 'mean_word_length': 2.2653399668325043, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 45, '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': '2615072', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1219, 'n_words': 287}