<commit_before><?php
namespace Ouzo;

use InvalidArgumentException;
use Ouzo\Db\ParameterType;
use Ouzo\Logger\Logger;
use PDO;
use PDOStatement;
use Ouzo\Db\Stats;
use Ouzo\Utilities\Arrays;
use Ouzo\Utilities\Objects;

class Db
{
    /**
     * @var PDOStatement
     */
    public $query = '';
    /**
     * @var PDO
     */
    public $_dbHandle = null;

    protected $_fetchMode = PDO::FETCH_ASSOC;

    private static $_instance;
    public $_startedTransaction = false;

    public function __construct($loadDefault = true)
    {
        if ($loadDefault) {
            $configDb = Config::getValue('db');
            if (!empty($configDb))
                $this->connectDb($configDb);
        }
    }

    public static function getInstance()
    {
        if (!self::$_instance) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    public function connectDb($params = array())
    {
        $dsn = $params['driver'] . ':host=' . $params['host'] . ';port=' . $params['port'] . ';dbname=' . $params['dbname'] . ';user=' . $params['user'] . ';password=' . $params['<PASSWORD>'];
        $this->_dbHandle = new PDO($dsn, $params['user'], $params['pass']);
        return $this;
    }

    static public function callFunction($functionName, $parameters)
    {
        $db = self::getInstance();
        $bindParams = Arrays::toArray($parameters);
        $paramsQueryString = implode(',', array_pad(array(), sizeof($bindParams), '?'));
        return Arrays::first($db->query("SELECT $functionName($paramsQueryString)", $parameters)->fetch());<commit_msg>Setting charset to db connection.<commit_after><?php
namespace Ouzo;

use InvalidArgumentException;
use Ouzo\Db\ParameterType;
use Ouzo\Logger\Logger;
use PDO;
use PDOStatement;
use Ouzo\Db\Stats;
use Ouzo\Utilities\Arrays;
use Ouzo\Utilities\Objects;

class Db
{
    /**
     * @var PDOStatement
     */
    public $query = '';
    /**
     * @var PDO
     */
    public $_dbHandle = null;

    protected $_fetchMode = PDO::FETCH_ASSOC;

    private static $_instance;
    public $_startedTransaction = false;

    public function __construct($loadDefault = true)
    {
        if ($loadDefault) {
            $configDb = Config::getValue('db');
            if (!empty($configDb))
                $this->connectDb($configDb);
        }
    }

    public static function getInstance()
    {
        if (!self::$_instance) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    public function connectDb($params = array())
    {
        $dsn = $params['driver'] . ':host=' . $params['host'] . ';port=' . $params['port'] . ';dbname=' . $params['dbname'] . ';user=' . $params['user'] . ';password=' . $params['<PASSWORD>'];
        $dsn .= Arrays::getValue($params, 'charset') ? ';charset=' . Arrays::getValue($params, 'charset') : '';
        $this->_dbHandle = new PDO($dsn, $params['user'], $params['pass']);
        return $this;
    }

    static public function callFunction($functionName, $parameters)
    {
        $db = self::getInstance();
        $bindParams = Arrays::toArray($parameters);
        $paramsQueryString = implode(',', array_pad(array(), sizeof($bindParams), '?'));
        return Arrays::first($db->query("SELECT $functionName($paramsQueryString)", $parameters)->fetch());
{'fraction_non_alphanumeric': 0.17154811715481172, 'fraction_numerical': 0.0, 'mean_word_length': 2.869364161849711, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '2919811', 'n_tokens_mistral': 1027, 'n_tokens_neox': 1006, 'n_words': 211}