S
S
symnoob2018-05-26 20:39:10
symfony
symnoob, 2018-05-26 20:39:10

Symfony 4 - Doctrine - Repository how to pull the correct data type??

Hello Forum,
I have a problem with the data type,
here is the method from my repository:

public function getAllIds($objektId, $uid):array
    {
        $conn = $this->getEntityManager()->getConnection();

        $sql = '
        SELECT o.id as id, a.id as aid,l.id as lid FROM immo_miete o
        LEFT JOIN immo_ausstattung a 
        ON o.id = a.fk_mid_id
        LEFT JOIN immo_lage l 
        ON o.id=l.fk_mid_id
        WHERE o.id = :objektId
        AND o.uid_id=:uid
        ORDER BY o.id ASC
        ';
        $stmt = $conn->prepare($sql);
        $stmt->execute(['objektId' => $objektId, 'uid' => $uid]);

        
        return $stmt->fetch();
    }

when i check variables from my controller, for
some reason all variables from array are string
$ids = $this
            ->entityManager
            ->getRepository(Objekt::class)
            ->getAllIds(1, $this->uid);

        echo gettype ($ids['id']);

id in dbms is marked as integer
what am i doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2018-05-26
@symnoob

by default, pdo receives numbers as strings, and this, if desired, is simply treated.
recipe for pdo - Is it possible to get a number when querying the database?
recipe specifically for doctrine - https://coderwall.com/p/goyc8w/how-to-stop-doctrin...

V
voronkovich, 2018-05-26
@voronkovich

No way. Doctrine does not cast data types when executing a regular SQL query. Use array_map .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question