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.

Phalcon Mysql scanning error

When executing this following code on my website

$login = $this->cookies->get('login');

$loggedinas = $login->getValue();

$user = Users::findFirst("username = '" . $loggedinas . "'");

The following error is thrown at me:

PhalconException: Scanning error before 'pentacore...' when parsing: SELECT [Users].* FROM [Users] WHERE username = 'pentacore (89)

And i cant really seem to get my head around it, The code snippet worked in another Controller, but not here.

Any ideas?

edited Oct '14

Use the ORM that way could expose your application to SQL injections, you can better write:

$user = Users::findFirstByUsername($loggedinas);
$user = Users::findFirst(array("username = ?0", "bind" => array($loggedinas)));


Thank you, that 2nd line worked perfectly, The 1st one didnt, might just be me thats stupid.


I have fixed it :)


ah, that worked much better, and i gotta say, going from using raw php to using phalcon sure is a relief :)


I ran into another problem while doing this tho, when i try to fetch variables from $user i get

Trying to get property of non-object


It means the record could not be found:

$user = Users::findFirstByUsername($loggedinas);
if (!$user) {
   echo "user does not exist";

edited Oct '14

well, the thing is that it properly fetches "pentacore" from the cookie, and passes it to the model, and i'm 100% sure that the username exists, since when i use the same line of code on another page on the site i can fetch the values from $user


hmm when i manually enter

$user = Users::findFirstByUsername("pentacore");

it works, however

$user = Users::findFirstByUsername($loggedinas);

does not seem to work, even if

echo $loggedinas;

returns pentacore....