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

HELP! `Exception The argument is not initialized or iterable()`

Hey can someone help me out with this? I’m trying to use a Phalcon query to insert models. Here is my code:

            $phql = "INSERT INTO CompanyModel (
                name, 
                about, 
                current_average_rating, 
                timestamp_updated, 
                timestamp_expires, 
                type, 
                profile_picture, 
                address_line_1, 
                address_line_2, 
                address_city, 
                address_state, 
                address_zip, 
                lat, 
                lon, 
                point, 
                phone
            )
            VALUES (
                :name:,
                NULL,
                :current_average_rating:,
                DEFAULT,
                DEFAULT,
                :type:,
                NULL,
                :address_line_1:,
                :address_line_2:,
                :address_city:,
                :address_state:,
                :address_zip:,
                :lat:,
                :lon:,
                ST_GEOMFROMTEXT('POINT({$companyArray['lon'] {$companyArray['lat']})'),
                :phone:
            )";

            $query = $this->modelsManager->executeQuery($phql, $companyArray);
            return $this->sendResponse($query);

but I keep getting this error:

Exception The argument is not initialized or iterable() 
    phalcon/mvc/model/query.zep:281 Phalcon\Mvc\Model\Query::_getQualified
    [internal] Phalcon\Mvc\Model\Query::_getExpression
    [internal] Phalcon\Mvc\Model\Query::_prepareInsert
    [internal] Phalcon\Mvc\Model\Query::parse
    [internal] Phalcon\Mvc\Model\Query::execute
    [internal] Phalcon\Mvc\Model\Manager::executeQuery

It’s failing on the $query = $this->modelsManager->executeQuery($phql, $companyArray); line.

I’ve verified that $companyArray is actually an array and has all the necessary attrs to bind.

Please help!

I know this don't solve a problem but why you just not normally do something like:

$model = new CompanyModel($companyArray);
$model->create();

?

I'm using a MySQL Spatial function ST_GEOMFROMTEXT() and the standard model create way was giving me problems interpreting that function. I’d like to avoid that and do the standard PHQL way, but if this doesn’t work maybe I’ll explore that more.

I know this don't solve a problem but why you just not normally do something like:

$model = new CompanyModel($companyArray);
$model->create();

?

edited Oct '16

You can't use PHQL or Models for such specific query. You need to go with PDO/MySQL.

https://docs.phalcon.io/en/latest/api/Phalcon_Db_Adapter_Pdo_Mysql.html

edited Oct '16

Ust mysql trigger and that's it for setting value of this field.