We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

FindFirst bind params doesn't work

Hello,

Phalcon 1.3.3, Percona DB 5.6, Ubuntu.

Trying to get records from db through ORM, all variations doesn't work - i see in mysql log (created by code based on EventsManager injection) queries with bind templates but not actual data.

Code:

            $types = array(
                "guid" => Column::BIND_PARAM_STR,
            );

            $parameters = array(
                "columns" => "parent_id",
                "conditions" => "guid = :guid:",
                "bind" => array("guid" => $guid),
                "bindTypes" => $types
            );

            $category = GoodsCategories::findFirst($parameters);

In my mysql_query.log:

[Sun, 09 Nov 14 05:04:58 +0300][INFO] SELECT goods_categories.parent_id AS parent_id FROM goods_categories WHERE goods_categories.guid = :guid LIMIT 1

As you see, "guid" param not binded, one colon left. Equal results with "conditions" => "guid = ?0" or Criteria-style query.

Query works perfect without binds:

$category = GoodsCategories::findFirst("guid = $guid");

but i lose advanages of bind params.

Model is very simple and doesn't have any relations, only fields with getters/setters: id, parent_id, guid

Where is problem?

Thank you.



33.8k

:guid? I think it's :guid:.



1.3k

In bind array is ":guid:", in log - ":guid", not variable value.



1.3k
Accepted
answer

Figured problem. Thi is s no problem with bind in findFirst, problem in db loggind logic via EventsManager which not tracked binded values.

Used db logging example from https://stackoverflow.com/questions/25285851/how-to-properly-initialize-database-connection-in-phalcon#answer-25306713

(Want fix, closed)



6.9k

@cnpait You resolved your problem, that try/catch block is an excellent solution to your problem.. I'm just not sure you what you still need in the form of a fix? Your (Want fix, closed) comment has me confused. If your own answer solved it, please mark it as the acceptable answer :)