PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] CakePHP and tinyint as boolean

 February 03, 2022     cakephp, php     No comments   

Issue

How can I force CakePHP 2.x to retrieve tinyint database column not as boolean but as tinyint?

MySQL:

Column        |    type
-------------------------------
...           |    ...
category_id   |    tinyint(1)
...           |    ...

CakePHP:

$this->request->data = $this->Question->read();
var_dump($this->request->data['Question']['category']);

The value is always 0 (if the question I'm fetching as the category id 0) or 1 (if the question has any other category id).


Solution

Use TINYINT(2) instead. If the length is 1, Cake sees it as a boolean.



Answered By - jeremyharris
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing