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

View mysql in phalcon

How to call a view mysql from phalcon I'm doing this in my phalcon controller:

$phql = "select id,description,name,dni from ViewUser where name like '%mark%' ";

$usuario = $this->modelsManager->executeQuery($phql);

Apparently I'm getting an error processing the where, why if yo process this:

$phql = "select id,description,name,dni from ViewUser";

$usuario = $this->modelsManager->executeQuery($phql);

I no longer get error. For the call of the view, already create my model ViewUser. I do not know what is wrong when I put the conditions in the WHERE.

Any help is welcome. Thank.

edited Feb '17

I am wrong too

$Q = $this->request->getPost("name");

$query = Criteria::fromInput($this->di, 'ViewUser', $_POST);

$query->orWhere("name like '%$Q%' ");

$this->persistent->parameters = $query->getParams();

db:beforeQuery event, also you should just have exception what is wrong.

Be aware of SQL injection! Always bind the input data you inject to the sql query

read more here

I am wrong too

$Q = $this->request->getPost("name");

$query = Criteria::fromInput($this->di, 'ViewUser', $_POST);

$query->orWhere("name like '%$Q%' ");

$this->persistent->parameters = $query->getParams();

edited Feb '17

Exactly, use binding.

$query->orWhere("name like :q:", ['q' => "%$Q%"]);