0

Here is my query in CakePHP 3.x

public function confirmation($token){
    $result = $this->Users->findAllByVerificationCode($token);
    debug($result->first());
    die(); 
}

If the variable $token is too long, the result is always null, but if i make it short, i get a result.

What is going on?

Br.sasa
  • 49
  • 1
  • 8

2 Answers2

0

Check the database schema. It's possible that your token field is too small for the data that you're putting into it, and the tokens are being truncated.

CoderCreative
  • 225
  • 1
  • 2
  • 9
  • i already checked my database, i tried using find with condition, i also wrote sql query but the result always null, but each time i try with short `$token` i get a result. – Br.sasa Mar 02 '16 at 23:24
  • `debug($result)` shows me the sql query, everyhing is correct,both values `$token` and `verification_code` are identical. but the result always `null` – Br.sasa Mar 02 '16 at 23:32
  • This still sounds like a truncation issue to me (assuming you're using MySQL). How long is the longest token you're saving? And what data type and length is the underlying database field? – CoderCreative Mar 02 '16 at 23:33
  • Problem solved, i didn't notice the variable type in my database, it's an integer, the token also is combination of numbers, but of type string. – Br.sasa Mar 02 '16 at 23:48
  • Normally that would work (as you know, because it worked for you with smaller tokens) but there are specific limits on the lengths of MySQL numeric data types that would make longer numeric strings truncate when stored. In this case you'd want to consider using a larger integer type (e.g. an unsigned bigint) OR a suitably-sized varchar. I'm glad your problem is solved anyway, if my answer helped please mark it as accepted. – CoderCreative Mar 02 '16 at 23:53
0

Problem solved, both $token and verification_code are identical, both are of combination of numbers, but one of them is of type Stringand the other is an Integer, and CakePHP doesn't convert the type automatically.

Br.sasa
  • 49
  • 1
  • 8
  • Please see the comments on my answer. The issue isn't that the datatype is different, it's that the datatype was not sufficient to hold the entire token, so the token was being truncated, as indicated in my answer. – CoderCreative Mar 03 '16 at 05:51