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

How Phalcon\Mvc\Model detect attribute data type?

I found in documentation https://docs.phalcon.io/hr/latest/db-models

Values assigned directly or via the array of attributes are escaped/sanitized according to the related attribute data type. So you can pass an insecure array without worrying about possible SQL injections

How Model detect type of data?



145.0k
Accepted
answer
edited Oct '17

By using metadata which are provided by annotations or information_schema table.

This is why on production you shoudn't use memory metadata adapter to avoid information_schema queries.



552

By using metadata which are provided by annotations or information_schema table.

This is why on production you shoudn't use memory metadata adapter to avoid information_schema queries.

Annotations are those that are generated when you create a model via cli? If annotation is in place, information_schema queries is still would perform?

If anootations are in place then don't but annotations don't provide i think everything features as normal metadata adapter using information_schema but not sure. Just best memcache adapter with Database strategy. Yea i think it's possible to generate models via cli with annotations.

I just don't use annotations beacause it's easier to develop. When i have ENV = DEV i just Memory adapter, when ENV = PROD i use Memcache adapter and that's it.

edited Oct '17

it is good idea to disable stats update on metadata fetching in MySQL/MariaDB conf (server level) via innodb_stats_on_metadata = 0

this will prevent statistic update when we query information_schema Most likely we do not want it anyway. This will not make Innodb to operate without statistics at all as Innodb will still compute statistics for the table first time it opens it.

I'm using custom models and I'm fetching meta data simply by this query:

        $getInfoSchema = <<<INFO
        SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE, COLUMN_KEY, EXTRA, PRIVILEGES
        FROM INFORMATION_SCHEMA.COLUMNS
        WHERE TABLE_SCHEMA = 'yourDBName'
        AND TABLE_NAME = 'yourTableName';
INFO;

I'm also using libMemcached as underlying adapter (Memcached server). Works like a charm.