<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'rdbms.DBConnection',
    'rdbms.mysqli.MySQLiResultSet',
    'rdbms.Transaction',
    'rdbms.StatementFormatter',
    'rdbms.mysqli.MysqliDialect'
  );

  /**
   * Connection to MySQL Databases
   *
   * @see      http://mysql.org/
   * @ext      mysqli
   * @test     xp://net.xp_framework.unittest.rdbms.TokenizerTest
   * @test     xp://net.xp_framework.unittest.rdbms.DBTest
   * @test     net.xp_framework.unittest.rdbms.integration.MySQLIntegrationTest
   * @purpose  Database connection
   */
  class MySQLiConnection extends DBConnection {
    protected $result= NULL;

    static function __static() {
      if (extension_loaded('mysqli')) {
        DriverManager::register('mysql+i', new XPClass(__CLASS__));
      }
    }

    /**
     * Constructor
     *
     * @param   rdbms.DSN dsn
     */
    public function __construct($dsn) { 
      parent::__construct($dsn);
      $this->formatter= new StatementFormatter($this, new MysqliDialect());
    }

    /**
     * Set Timeout
     *
     * @param   int timeout
     */
    public function setTimeout($timeout) {
      ini_set('mysql.connect_timeout', $timeout);
      parent::setTimeout($timeout);
    }

    /**
     * Connect
     *
     * @param   bool reconnect default FALSE
     * @return  bool success
     * @throws  rdbms.SQLConnectException
     */
    public function connect($reconnect= FALSE) {
      if (is_object($this->handle)) return TRUE;  // Already connected
      if (!$reconnect && (FALSE === $this->handle)) return FALSE;    // Previously failed connecting

      // Connect via local sockets if "." is passed. This will not work on
      // Windows with the mysqlnd extension (see PHP bug #48082: "mysql_connect
      // does not work with named pipes"). For mysqlnd, we default to mysqlx
      // anyways, so this works transparently.
      $host= $this->dsn->getHost();
      if ('.' === $host) {
        $sock= $this->dsn->getProperty('socket', NULL);
        if (0 === strncasecmp(PHP_OS, 'Win', 3)) {
          $connect= '.';
          if (NULL !== $sock) $sock= substr($sock, 9);   // 9 = strlen("\\\\.\\pipe\\")
        } else {
          $connect= 'localhost';
        }
      } else if ('localhost' === $host) {
        $connect= '127.0.0.1';   // Force TCP/IP
      }

      $this->handle= mysqli_connect(
        ($this->flags & DB_PERSISTENT ? 'p:' : '').$connect,
        $this->dsn->getUser(), 
        $this->dsn->getPassword(),
        $this->dsn->getDatabase(),
        $this->dsn->getPort(3306),
        $sock
      );<commit_msg>- Fix connect() method for mysql+i driver<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'rdbms.DBConnection',
    'rdbms.mysqli.MySQLiResultSet',
    'rdbms.Transaction',
    'rdbms.StatementFormatter',
    'rdbms.mysqli.MysqliDialect'
  );

  /**
   * Connection to MySQL Databases
   *
   * @see      http://mysql.org/
   * @ext      mysqli
   * @test     xp://net.xp_framework.unittest.rdbms.TokenizerTest
   * @test     xp://net.xp_framework.unittest.rdbms.DBTest
   * @test     net.xp_framework.unittest.rdbms.integration.MySQLIntegrationTest
   * @purpose  Database connection
   */
  class MySQLiConnection extends DBConnection {
    protected $result= NULL;

    static function __static() {
      if (extension_loaded('mysqli')) {
        DriverManager::register('mysql+i', new XPClass(__CLASS__));
      }
    }

    /**
     * Constructor
     *
     * @param   rdbms.DSN dsn
     */
    public function __construct($dsn) { 
      parent::__construct($dsn);
      $this->formatter= new StatementFormatter($this, new MysqliDialect());
    }

    /**
     * Set Timeout
     *
     * @param   int timeout
     */
    public function setTimeout($timeout) {
      ini_set('mysql.connect_timeout', $timeout);
      parent::setTimeout($timeout);
    }

    /**
     * Connect
     *
     * @param   bool reconnect default FALSE
     * @return  bool success
     * @throws  rdbms.SQLConnectException
     */
    public function connect($reconnect= FALSE) {
      if (is_object($this->handle)) return TRUE;  // Already connected
      if (!$reconnect && (FALSE === $this->handle)) return FALSE;    // Previously failed connecting

      // Connect via local sockets if "." is passed. This will not work on
      // Windows with the mysqlnd extension (see PHP bug #48082: "mysql_connect
      // does not work with named pipes"). For mysqlnd, we default to mysqlx
      // anyways, so this works transparently.
      $host= $this->dsn->getHost();
      $sock= NULL;
      if ('.' === $host) {
        $sock= $this->dsn->getProperty('socket', NULL);
        if (0 === strncasecmp(PHP_OS, 'Win', 3)) {
          $host= '.';
          if (NULL !== $sock) $sock= substr($sock, 9);   // 9 = strlen("\\\\.\\pipe\\")
        } else {
          $host= 'localhost';
        }
      } else if ('localhost' === $host) {
        $host= '127.0.0.1';   // Force TCP/IP
      }

      $this->handle= mysqli_connect(
        ($this->flags & DB_PERSISTENT ? 'p:' : '').$host,
        $this->dsn->getUser(), 
        $this->dsn->getPassword(),
        $this->dsn->getDatabase(),
        $this->dsn->getPort(3306),
        $sock
      );
{'fraction_non_alphanumeric': 0.1528433780464765, 'fraction_numerical': 0.007179293406385793, 'mean_word_length': 2.2558425584255843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7484467', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1669, 'n_words': 376}