Pop\Db\Sql::setDb PHP Method

setDb() public method

Set the database object
public setDb ( Db $db ) : Sql
$db Db
return Sql
    public function setDb(Db $db)
    {
        $this->db = $db;
        $adapter = strtolower($this->db->getAdapterType());
        if (strpos($adapter, 'mysql') !== false) {
            $this->dbType = self::MYSQL;
            $this->quoteIdType = self::BACKTICK;
        } else {
            if (strpos($adapter, 'oracle') !== false) {
                $this->dbType = self::ORACLE;
                $this->quoteIdType = self::DOUBLE_QUOTE;
            } else {
                if (strpos($adapter, 'pgsql') !== false) {
                    $this->dbType = self::PGSQL;
                    $this->quoteIdType = self::DOUBLE_QUOTE;
                } else {
                    if (strpos($adapter, 'sqlite') !== false) {
                        $this->dbType = self::SQLITE;
                        $this->quoteIdType = self::DOUBLE_QUOTE;
                    } else {
                        if (strpos($adapter, 'sqlsrv') !== false) {
                            $this->dbType = self::SQLSRV;
                            $this->quoteIdType = self::BRACKET;
                        }
                    }
                }
            }
        }
        return $this;
    }

Usage Example

Exemplo n.º 1
0
 public function testSetAndGetDb()
 {
     $db = Db::factory('Sqlite', array('database' => __DIR__ . '/../tmp/test.sqlite'));
     $s = new Sql($db, 'users');
     $s->setDb($db);
     $this->assertInstanceOf('Pop\\Db\\Db', $s->getDb());
     $this->assertInstanceOf('Pop\\Db\\Adapter\\Sqlite', $s->adapter());
 }