Getting bit field using mysql_query ()

Here is my code:

$query = "SELECT Username, EmailVerified, Blocked FROM user"; $result = mysql_query($query, $link); $row = mysql_fetch_assoc($result); print_r($row); 

The Username field, the string and EmailVerified and Blocked are of type bits . The print_r($row) displays the value of the Username field, but not the other two. I tried mysql_fetch_object (), mysql_fetch_row (), mysql_fetch_array (), but the same result.

Can't we get bit fields with mysql_query ()?

+4
source share
3 answers

I think you need to attribute the BIT field to an integer →

 SELECT Username, CAST(EmailVerified AS unsigned integer) AS EmailV, CAST(Blocked AS unsigned integer) AS Block FROM User 
+8
source

Yes, you can, but they are extracted as strings and most likely become non-printable characters. You can get the values ​​as numbers as follows:

 $query = "SELECT Username, EmailVerified, Blocked FROM user"; $result = mysql_query($query, $link); $row = mysql_fetch_assoc($result); $row['EmailVerified'] = ord( $row['EmailVerified'] ); $row['Blocked'] = ord( $row['Blocked'] ); print_r($row); 
+4
source

Instead of using BIT and converting it every time you need to use it, you can use BOOL (which is already TINYINT ) and saves the values ​​TRUE (1) or FALSE (0).

+2
source

Source: https://habr.com/ru/post/1389910/


All Articles