Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

MYSQLI_GROUP_FLAG and MYSQLI_NUM_FLAG are both 32768

Codes here !

Moderators: macek, egami, gesf

MYSQLI_GROUP_FLAG and MYSQLI_NUM_FLAG are both 32768

Postby Jabber » Fri Oct 12, 2012 8:35 am

Hi you all,

i'm using PHP 5.3.10 and Mysql 5.5.2.4, i execute this code:
$result = $conn->query( $sql ); // $sql is "SELECT * FROM mytable;"
$headers = $result->fetch_fields();
$id=$headers[0];
echo ($id->flags & MYSQLI_NUM_FLAG ); // -> 32768
echo ($id->flags & MYSQLI_GROUP_FLAG ); // -> 32768

I get the same number 32768, is it a bug ?
But my table id ($headers[0]) is not part of a "GROUP BY" clause.

Here is var_dump of "id" field:
Object (
| name = String(2) "id"
| orgname = String(2) "id"
| table = String(4) "info_table"
| orgtable = String(4) "info_table"
| def = String(0) ""
| db = String(4) "gpro"
| catalog = String(3) "def"
| max_length = Integer(1) 2
| length = Integer(1) 4
| charsetnr = Integer(2) 63
| flags = Integer(5) 49667
| type = Integer(1) 2
| decimals = Integer(1) 0
)

I've tried all mysqli flag constants (see http://php.net/manual/en/mysqli.constants.php) by bitwise operator ( $id & CONSTANT ), these are the flag constants returned not zero:
MYSQLI_NOT_NULL_FLAG
MYSQLI_PRI_KEY_FLAG
MYSQLI_AUTO_INCREMENT_FLAG
MYSQLI_PART_KEY_FLAG
MYSQLI_NUM_FLAG
MYSQLI_GROUP_FLAG

"id" field is of smallint type.


Do you know somethig about this behavior?
Could this be a bug?
Jabber
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Oct 12, 2012 8:29 am

Re: MYSQLI_GROUP_FLAG and MYSQLI_NUM_FLAG are both 32768

Postby seandisanti » Fri Oct 12, 2012 9:50 am

is the $id->flags==32768? i think it might be and that would explain your results.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 775
Joined: Mon Oct 01, 2012 12:32 pm

Re: MYSQLI_GROUP_FLAG and MYSQLI_NUM_FLAG are both 32768

Postby seandisanti » Fri Oct 12, 2012 9:57 am

the way that a bitwise and comparison works, is by taking the binary representation of 2 numbers, and totalling their common bits. for example,

Code: Select all
<?php echo 2&3; ?>
returns 2 because this comparison takes place:
10
11
--
10
no matter what you change the second number to, you'll never get a greater number from the comparison than 2, because it is impossible to have a common bit of greater value than one of your numbers. I hope that helps a bit.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 775
Joined: Mon Oct 01, 2012 12:32 pm

Re: MYSQLI_GROUP_FLAG and MYSQLI_NUM_FLAG are both 32768

Postby Jabber » Fri Oct 12, 2012 12:46 pm

As you can see above, $id->flags is 49667

Bitwise operator "&" is a login AND bit per bit,
in fact mysql flag constants are powers of 2, see:
Array (14) (
| ['MYSQLI_NOT_NULL_FLAG'] = Integer(1) 1
| ['MYSQLI_PRI_KEY_FLAG'] = Integer(1) 2
| ['MYSQLI_UNIQUE_KEY_FLAG'] = Integer(1) 4
| ['MYSQLI_MULTIPLE_KEY_FLAG'] = Integer(1) 8
| ['MYSQLI_BLOB_FLAG'] = Integer(2) 16
| ['MYSQLI_UNSIGNED_FLAG'] = Integer(2) 32
| ['MYSQLI_ZEROFILL_FLAG'] = Integer(2) 64
| ['MYSQLI_ENUM_FLAG'] = Integer(3) 256
| ['MYSQLI_AUTO_INCREMENT_FLAG'] = Integer(3) 512
| ['MYSQLI_TIMESTAMP_FLAG'] = Integer(4) 1024
| ['MYSQLI_SET_FLAG'] = Integer(4) 2048
| ['MYSQLI_PART_KEY_FLAG'] = Integer(5) 16384
| ['MYSQLI_NUM_FLAG'] = Integer(5) 32768
| ['MYSQLI_GROUP_FLAG'] = Integer(5) 32768
)

The real problem is that MYSQLI_GROUP_FLAG and MYSQLI_NUM_FLAG
are two different constants but their value is 32768.
Another problem is, as i already told above, php is telling me that
$id field is a part of "GROUP BY" clause, but this is FALSE.
In fact my query is very simple: "SELECT * FROM mytable;"

I'm wondering if it's a bug.

J
Jabber
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Oct 12, 2012 8:29 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron