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

Phalcon 2 problem with model has special name

I have a problem which model since upgraded my application to phalcon 2.

My application has a model named "Option" (with table option).

Table option:

id  int(11) Auto Increment   
title   varchar(255)     
key varchar(255)     
content text NULL

With phalcon 1.3, function getOption below runs perfectly:

public function getOption($key) {
    $option = $this->function->get_result('option', 'findFirstByKey', $key);
    if ($option) {
        return array('status' => 'ok', 'data' => $option->toArray(), 'class' => 'option');
    }

    return array('status' => 'error', 'messages' => array('No record found'));
}

public function get_class_name($class) {
    $class_name = ucfirst($class);

    return 'Bcdcnt\Models\\' . $class_name;
}

public function get_result($class, $method, $args) {
    $class_name = $this->get_class_name($class);

    return call_user_func_array(array($class_name, $method), array($args));
}

But when switches to phalcon 2, the function return the error likes this:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option WHERE option.key = 'home_playlist_title' LIMIT 1' at line 1

Does the special model name (option) cause the error above?

Could you please submit this on Github as a bug?



1.2k

Having the same problem with a table called order:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order WHERE order.id = 9808 LIMIT 1'