We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Empty Model::findFirst($id) with existing Database Entry - PDO works

Hi there,

while trying to get an Db Entry with Model::findFirst() it returns false even though the sql.log shows the right query.

Di::getDefault()['db']->query('SELECT * FROM model LIMIT 1')->fetchAll() returns the correct result.

When assigning those results to Model and doing a setFoo('bar')->save(), DB is untouched.

Can anybody help me here??

--Holger

hi @holgersielaff check your model source setSource() and getSource(). docs

Tip: better use Model::findFirst(['conditions' => 'id = {id:int}', 'bind' => ['id' => $id]]); instead of Model::findFirst($id)

Good luck

Posting the (relevant) source of your model class could help... Also, which version of PHP + Phalcon are you running?

Hi all and thank you for the replies,

my system specs (Dockerfile) are:

FROM ubuntu:bionic
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
    apache2 \
    libapache2-mod-fcgid 
    php-fpm \
    php-mysql \
    curl \
    ...
RUN  curl -s "https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh" | bash && apt-get install -y --no-install-recommends php7.2-phalcon
RUN a2enmod rewrite headers proxy_fcgi

Database is mounted via -v /var/run/mysql/mysql.sock:/var/run/mysql/mysql.sock

Models are generated via phalcon-devtools (--get-set --abstract)

Does this help?

--Holger



581
Accepted
answer

Hi all,

i solved it by setting

"options" => [
            \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
        ]

in db config

Thanks, Holger