Habari\MySQLConnection::connect PHP Метод

connect() публичный Метод

Extends default connection method. It will be useful in order to allow accents and other DB-centric global commands.
public connect ( string $connect_string, string $db_user, string $db_pass ) : boolean
$connect_string string a PDO connection string
$db_user string the database user name
$db_pass string the database user password
Результат boolean true on success, false on error
    public function connect($connect_string, $db_user, $db_pass)
    {
        // If something went wrong, we don't need to exec the specific commands.
        if (!parent::connect($connect_string, $db_user, $db_pass)) {
            return false;
        }
        $this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
        // Everything is OK. Let's update the charset!
        if (!defined('MYSQL_CHAR_SET')) {
            define('MYSQL_CHAR_SET', 'UTF8');
        }
        // SET NAMES defines character_set_client, character_set_results, and character_set_connection (which implicitly sets collation_connection) and therefore covers everything SET CHARACTER SET does, but uses the character set we tell it to, ignoring what the database is configured to use
        // 	http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html
        $this->exec('SET NAMES ' . MYSQL_CHAR_SET);
        return true;
    }