es131245 Posted October 4, 2010 Share Posted October 4, 2010 ive got some "private" parts of the site which i want to limit access by SQL table (like licence limited files and MODERATOR panels)so USER table looks likeid login pass share moderator grantedUser1 root pass 1 1 12 friends code 1 0 13 guest la-la 0 0 0data type of the parts is BITi wanted to make a 0 a default and 1 is access granted but now i see that for 1 i get SOH symbol and for 0 i get � and NULL works for NULLive tried to set a boolean value in phpa i get true for 1 & 0 and false for NULLi dont want to use TINYINT because its actualy 256 and just dont want to... Link to comment Share on other sites More sharing options...
justsomeguy Posted October 4, 2010 Share Posted October 4, 2010 for 1 i get SOH symbol and for 0 i get � and NULL works for NULLIf a bit field is printing characters then for whatever reason it's being interpreted as an ASCII character instead of a number.ive tried to set a boolean value in phpa i get true for 1 & 0 and false for NULLThat may be due to how you're assigning the value in PHP.i dont want to use TINYINT because its actualy 256 and just dont want to...I'm not sure what that means, but I always use unsigned tinyint fields of length 1 for these things. But if you just don't want to, then you don't want to. Link to comment Share on other sites More sharing options...
es131245 Posted October 4, 2010 Author Share Posted October 4, 2010 $permit_share=(boolean)$mysql_fetch_assoc['share'];last try was to make it boolean Link to comment Share on other sites More sharing options...
justsomeguy Posted October 4, 2010 Share Posted October 4, 2010 A string 0 will cast to false. What is the value of that field before the cast? Link to comment Share on other sites More sharing options...
es131245 Posted October 5, 2010 Author Share Posted October 5, 2010 here is all values ive gotmta is mysql_fetch_assoc['share']b is (boolean)mysql_fetch_assoc['share']1 mta=;b=1mta isset B isset mta =0 b=1 mta=true b=true0 mta=;b=1mta isset B isset mta =0 b=1 mta=true b=trueNULLmta = ; b =mta NOT set B issetmta=0 b=0mta=false b=false Link to comment Share on other sites More sharing options...
justsomeguy Posted October 5, 2010 Share Posted October 5, 2010 Yeah, it's reading that out as a character, not a number. It would probably be best to convert that to an integer or boolean in the SQL statement instead of in PHP, by the time PHP sees it it's a string. Link to comment Share on other sites More sharing options...
es131245 Posted October 6, 2010 Author Share Posted October 6, 2010 $permit=$mysql_fetch_assoc['permit']; $perm=$mysql_fetch_assoc['perm'];print($permit.'=');print((int)$permit.'<br />');print($perm.'=');print((int)$perm.'<br />');die();=0=0so tinyint is the only way&&USE mysql;SHOW COLUMNS user;USE $sitedb;ALTER TABLE $tablename MODIFY COLUMN $permit enum('N','Y'); Link to comment Share on other sites More sharing options...
justsomeguy Posted October 6, 2010 Share Posted October 6, 2010 You're still doing the conversion in PHP, I was suggesting you have MySQL convert the value in the SQL statement before it gets to PHP. Once it gets to PHP it's already a string, you need to do the conversion in MySQL.http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.