Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Exception: Call to undefined method Phalcon\Db\Adapter\Pdo\Mysql::selectcollection()

Hi There,

I got a question, I am getting this exception: Call to undefined method Phalcon\Db\Adapter\Pdo\Mysql::selectcollection().

I do not understand what I am missing here and where I need to put it. It occurs whenever I try to call this in the model:

...
public function initialize()
{
    $this->setConnectionService('connection');
    $this->setSource("table");
}
...

and it is defined on index as:

...
$di->set('connection', function(){
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
        "host" => "127.0.0.1",
        "username" => "username",
        "password" => "password",
        "dbname" => "database",
        "port" => 0000,
        'charset' => 'utf8',
    ));
});
...

I tried to look on the web but can't get anything to make it work. Please advice.

Thanks,



106.8k
Accepted
answer
edited May '16

selectcollection is just method for mongo, not for mysql, such an method just don't exist for mysql beacause you don't have collections in it.



3.6k

I was planning to use ORM. The model it is being referred to is a subclass of Models. Your assumption is correct, thanks. What I am puzzled now is that it is being seen as a collection instead of being a model.

This is the model:

class SomeModel extends Models
{
  public function initialize()
  {
    $this->setConnectionService('some_connection');
    $this->setSource("some_table");
  }
}

And when I am accessing it in the controller:

$result = SomeModel::find("some_field=1");

Did I miss something here?



3.6k

Ah, found it.

Instead of Model, I used Models. Apparently, Models was created that extends Collection that's why I was not able to notice about the error on using Model instead.

Thanks for clearing things up earlier. Cheers.