Ifsnop\Mysqldump\TypeAdapterFactory::create PHP Method

create() public static method

public static create ( string $c, PDO $dbHandler = null )
$c string Type of database factory to create (Mysql, Sqlite,...)
$dbHandler PDO
    public static function create($c, $dbHandler = null)
    {
        $c = ucfirst(strtolower($c));
        if (!TypeAdapter::isValid($c)) {
            throw new Exception("Database type support for ({$c}) not yet available");
        }
        $method = __NAMESPACE__ . "\\" . "TypeAdapter" . $c;
        return new $method($dbHandler);
    }

Usage Example

Example #1
0
 /**
  * Connect with PDO
  *
  * @return null
  */
 private function connect()
 {
     // Connecting with PDO
     try {
         switch ($this->dbType) {
             case 'sqlite':
                 $this->dbHandler = @new PDO("sqlite:" . $this->dbName, null, null, $this->pdoSettings);
                 break;
             case 'mysql':
             case 'pgsql':
             case 'dblib':
                 $this->dbHandler = @new PDO($this->dsn, $this->user, $this->pass, $this->pdoSettings);
                 // Execute init commands once connected
                 foreach ($this->dumpSettings['init_commands'] as $stmt) {
                     $this->dbHandler->exec($stmt);
                 }
                 // Store server version
                 $this->version = $this->dbHandler->getAttribute(PDO::ATTR_SERVER_VERSION);
                 break;
             default:
                 throw new Exception("Unsupported database type (" . $this->dbType . ")");
         }
     } catch (PDOException $e) {
         throw new Exception("Connection to " . $this->dbType . " failed with message: " . $e->getMessage());
     }
     $this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
     $this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler);
 }
All Usage Examples Of Ifsnop\Mysqldump\TypeAdapterFactory::create