LazyRecord\BaseModel::loadQuery PHP Method

loadQuery() public method

Load record from an sql query.
public loadQuery ( string $sql, array $args = [], string $dsId = null ) : Result
$sql string sql statement
$args array
$dsId string data source id $result = $record->loadQuery( 'select * from ....', array( ... ) , 'master' );
return Result
    public function loadQuery($sql, array $args = array(), $dsId = null)
    {
        if (!$dsId) {
            $dsId = $this->readSourceId;
        }
        $conn = $this->getConnection($dsId);
        $stm = $conn->prepare($sql);
        $stm->execute($args);
        if (false === ($this->_data = $stm->fetch(PDO::FETCH_ASSOC))) {
            return $this->reportError('Data load failed.', array('sql' => $sql, 'args' => $args));
        }
        return $this->reportSuccess('Data loaded', array('id' => isset($this->_data[$pk]) ? $this->_data[$pk] : null, 'sql' => $sql));
    }