Skip to content

Magento 2 – Is it bad practice to directly use SQL in php?

We are using a third party module. They have their own database tables and read out data from it by using direct SQL statements

app/code/Company/Foo/Model/Calculator.php

public function load_fugenMoertel($fugenMoertel) {

    $fugenMoertelTable = $this->_resource->getTableName( 'px_fugenmasse' );
    $binds = array(
        'moertel' => $fugenMoertel
    );

    /* with sku's */
    $query = "SELECT gewicht, gebindegroesse, packung FROM " . $fugenMoertelTable . " where artikelnummer = :moertel";


    $result = $this->connection->query( $query, $binds );
    while ( $row = $result->fetch() ) {
        $moertel['gewicht'] = $row['gewicht'];
        $moertel['groesse'] = $row['gebindegroesse'];
        $moertel['packung'] = $row['packung'];
    }     
    return $moertel;
}

Is this considered as bad practice? If yes, does it give any disadvantage? Why should you avoid it?