Prado\Data\ActiveRecord\TActiveRecord::getDbConnection PHP Method

getDbConnection() public method

Gets the current Db connection, the connection object is obtained from the TActiveRecordManager if connection is currently null.
public getDbConnection ( ) : TDbConnection
return TDbConnection current db connection for this object.
    public function getDbConnection()
    {
        if ($this->_connection === null) {
            $this->_connection = self::getActiveDbConnection();
        }
        return $this->_connection;
    }

Usage Example

 /**
  * @param TActiveRecord $record
  * @return TDataGatewayCommand
  */
 public function getCommand(TActiveRecord $record)
 {
     $conn = $record->getDbConnection();
     $connStr = $conn->getConnectionString();
     $tableInfo = $this->getRecordTableInfo($record);
     if (!isset($this->_commandBuilders[$connStr])) {
         $builder = $tableInfo->createCommandBuilder($record->getDbConnection());
         $command = new TDataGatewayCommand($builder);
         $command->OnCreateCommand[] = array($this, 'onCreateCommand');
         $command->OnExecuteCommand[] = array($this, 'onExecuteCommand');
         $this->_commandBuilders[$connStr] = $command;
     }
     $this->_commandBuilders[$connStr]->getBuilder()->setTableInfo($tableInfo);
     $this->_currentRecord = $record;
     return $this->_commandBuilders[$connStr];
 }