src/Entity/Repository.php
/**
     * Generic function for returning single record from a table based on pk
     *
     * @param $table
     * @param int $limit
     * @param int $offset
     * @return mixed
     */
Generic function for returning single record from a table based on pk
@param $table
@param int $limit
@param int $offset
@return mixed
Generic function for returning single record from a table based on pk @param $table @param int $limit @param int $offset @return mixed
public function findByPk($table, $pk_field, $id)
    {
        $table = preg_replace('/[^A-Za-z0-9_]+/', '', $table);
        $query = "SELECT * FROM `$table` where $pk_field = " . (int)$id;
        if ($result = $this->mysqli->query($query)) {
            return $result->fetch_assoc();
        }
    }
public function findByPk ( $ table , $ pk_field , $ id ) { $ table = preg_replace ( '/[^A-Za-z0-9_]+/' , '' , $ table ) ; $ query = " SELECT * FROM ` $ table ` where  $ pk_field  =  " . ( int ) $ id ; if ( $ result = $ this -> mysqli -> query ( $ query ) ) { return $ result -> fetch_assoc ( ) ; } }
Generic function for returning single record from a table based on pk
 @param $table
 @param int $limit
 @param int $offset
 @return mixed
Generic function for returning single record from a table based on pk @param $table @param int $limit @param int $offset @return mixed
// Make sure the table name does not have any dodgy chars in it // which might offer a way for SQL Injection // Select all the records from the current table. Yes I am using "Select *" here which I // would not do in real life. I'd explicitly select the fields, probably by using a field // list in each table class, or perhaps using annotations like Doctrine does