Granada\ORM::get_db PHP Method

get_db() public static method

Returns the PDO instance used by the the ORM to communicate with the database. This can be called if any low-level DB access is required outside the class. If multiple connections are used, accepts an optional key name for the connection.
public static get_db ( string $connection_name = self::DEFAULT_CONNECTION ) : PDO
$connection_name string Which connection to use
return PDO
    public static function get_db($connection_name = self::DEFAULT_CONNECTION)
    {
        self::_setup_db($connection_name);
        // required in case this is called before Idiorm is instantiated
        return self::$_db[$connection_name];
    }

Usage Example

Beispiel #1
0
 /**
  *
  * To create and save multiple elements, easy way
  * Using an array with rows array(array('name'=>'value',...), array('name2'=>'value2',...),..)
  * or a array multiple
  *
  */
 public function insert($rows, $ignore = false)
 {
     ORM::get_db()->beginTransaction();
     foreach ($rows as $row) {
         $class = $this->_class_name;
         $class::create($row)->save($ignore);
     }
     ORM::get_db()->commit();
     return ORM::get_db()->lastInsertId();
 }
All Usage Examples Of Granada\ORM::get_db
ORM