db::connect PHP Method

connect() static public method

It will only connect once and return that same connection for all following queries
static public connect ( ) : mixed
return mixed
    static function connect()
    {
        $connection = self::connection();
        $args = func_get_args();
        $host = a::get($args, 0, c::get('db.host', 'localhost'));
        $user = a::get($args, 1, c::get('db.user', 'root'));
        $password = a::get($args, 2, c::get('db.password'));
        $database = a::get($args, 3, c::get('db.name'));
        $charset = a::get($args, 4, c::get('db.charset', 'utf8'));
        // don't connect again if it's already done
        $connection = !$connection ? @mysql_connect($host, $user, $password) : $connection;
        // react on connection failures
        if (!$connection) {
            return self::error(l::get('db.errors.connect', 'Database connection failed'), true);
        }
        self::$connection = $connection;
        // select the database
        $database = self::database($database);
        if (error($database)) {
            return $database;
        }
        // set the right charset
        $charset = self::charset($charset);
        if (error($charset)) {
            return $charset;
        }
        return $connection;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 	Lezárja az adatbázis kapcsolatot (A PDO objektum-hoz a null értéket rendeli hozzá)
  */
 public static function close_connect()
 {
     if (self::$connect != null) {
         self::$connect = null;
     }
     return self::$connect;
 }
All Usage Examples Of db::connect