<commit_before><?php

 /* --------------------------------------------------------
 | Seed-PHP Microframework
 | @author <NAME> (<EMAIL>)
 | @version 0.5.3
 | @license MIT
 | @see http://github.com/abtzco/seed-php
 * -------------------------------------------------------- */

namespace Seed\Helper;

defined('SEED') or die('Direct script access is not allowed!');

class MySQL {

  private $_host = 'localhost';
  private $_port = '3306';
  private $_user = 'root';
  private $_pass = '';
  private $_base = 'test';
  private $_charset = 'utf8';

  // the connection resource
  private $_resource = null;

  // the last result count (since v0.3.0)
  private $_last_result_count = 0;

  function __construct( $config = null ) {

    if (!is_null($config)) {

      if (isset($config['host'])) {
        $this->setHost( $config['host'] );
      }

      if (isset($config['port'])) {
        $this->setPort( $config['port'] );
      }

      if (isset($config['base'])) {
        $this->setDatabase( $config['base'] );
      }

      if (isset($config['charset'])) {
        $this->setCharset( $config['charset'] );
      }

      if (isset($config['user']) && isset($config['pass'])) {
        $this->setCredential( $config['user'], $config['pass'] );
      }

    }

    return $this;

  } // __construct

  private function _escape ( $str = '' ) {
    if (!is_object( $this->_resource )) {
      return $str;
    }

    return (
        is_null($str)
          ? 'NULL'
          : (
            is_numeric($str) || is_bool($str)
              ? $str
              : (
                is_string($str)
                  ? "'{$this->_resource->real_escape_string($str)}'"
                  : $str
              )
          )
      );
  } // _escape

  public function setHost ($host = 'localhost', $port = '3306', $charset = 'utf8') {
    if (!empty($host) && !is_null($host)) {
      $this->_host = $host;
    }

    if (!empty($port) && !is_null($port)) {
      $this->_port = $port;
    }

    if (!empty($charset) && !is_null($charset)) {
      $this->_charset = $charset;
    }

    return $this;
  } // setHost

  public function setPort ($port = '3306') {
    if (!empty($port) && !is_null($port)) {
      $this->_port = $port;
    }
    return $this;
  } // setPort

  public function setCredential ($user = 'root', $pass = '') {
    if (!empty($user) && !is_null($user)) {
      $this->_user = $user;
    }

    if (!empty($pass) && !is_null($pass)) {
      $this->_pass = $pass;
    }<commit_msg>Adds a new public method to escape strings<commit_after><?php

 /* --------------------------------------------------------
 | Seed-PHP Microframework
 | @author <NAME> (<EMAIL>)
 | @version 0.6.0
 | @license MIT
 | @see http://github.com/abtzco/seed-php
 * -------------------------------------------------------- */

namespace Seed\Helper;

defined('SEED') or die('Direct script access is not allowed!');

class MySQL {

  private $_host = 'localhost';
  private $_port = '3306';
  private $_user = 'root';
  private $_pass = '';
  private $_base = 'test';
  private $_charset = 'utf8';

  // the connection resource
  private $_resource = null;

  // the last result count (since v0.3.0)
  private $_last_result_count = 0;

  function __construct( $config = null ) {

    if (!is_null($config)) {

      if (isset($config['host'])) {
        $this->setHost( $config['host'] );
      }

      if (isset($config['port'])) {
        $this->setPort( $config['port'] );
      }

      if (isset($config['base'])) {
        $this->setDatabase( $config['base'] );
      }

      if (isset($config['charset'])) {
        $this->setCharset( $config['charset'] );
      }

      if (isset($config['user']) && isset($config['pass'])) {
        $this->setCredential( $config['user'], $config['pass'] );
      }

    }

    return $this;

  } // __construct

  private function _escape ( $str = '' ) {
    if (!is_object( $this->_resource )) {
      return $str;
    }

    return (
        is_null($str)
          ? 'NULL'
          : (
            is_numeric($str) || is_bool($str)
              ? $str
              : (
                is_string($str)
                  ? "'{$this->_resource->real_escape_string($str)}'"
                  : $str
              )
          )
      );
  } // _escape

  /**
   * Escapes an string to be used in the SQL statement.
   * Since version 0.6.0.
   * 
   * @param string $str
   * @return string
   */
  public function escape( $str = '' ) {
    return $this->_escape($str);
  } // escape

  public function setHost ($host = 'localhost', $port = '3306', $charset = 'utf8') {
    if (!empty($host) && !is_null($host)) {
      $this->_host = $host;
    }

    if (!empty($port) && !is_null($port)) {
      $this->_port = $port;
    }

    if (!empty($charset) && !is_null($charset)) {
      $this->_charset = $charset;
    }

    return $this;
  } // setHost

  public function setPort ($port = '3306') {
    if (!empty($port) && !is_null($port)) {
      $this->_port = $port;
    }
    return $this;
  } // setPort

  public function setCredential ($user = 'root', $pass = '') {
    if (!empty($user) && !is_null($user)) {
      $this->_user = $user;
    }

    if (!empty($pass) && !is_null($pass)) {
      $this->_pass = $pass;
    }
{'fraction_non_alphanumeric': 0.22635071090047393, 'fraction_numerical': 0.008530805687203791, 'mean_word_length': 1.9165284687672748, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 36, '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': '2319794', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1635, 'n_words': 356}