I have been lately working with prepared statements and I noticed something rather buggy...
I have an integer column in MySQL InnoDB table which is unsigned so it is capable of handling values between 0 and 4294967295 (including the boundaries). However, something nasty is going on with the MySQLI STMT -class. Look:
Code: Select all
$stmt -> bind_param("i",$a);
$a = 0;expected? yes
Code: Select all
$stmt -> bind_param("i",$a);
$a = 1;expected? yes
Code: Select all
$stmt -> bind_param("i",$a);
$a = -1;expected? yes
Code: Select all
$stmt -> bind_param("i",$a);
$a = 2147483647;expected? yes
Code: Select all
$stmt -> bind_param("i",$a);
$a = 2147483648;expected? NO! WTF ??
Code: Select all
$stmt -> bind_param("i",$a);
$a = 4294967295;expected? NO! WTF ??
Code: Select all
$stmt -> bind_param("i",$a);
$a = 4294967296;expected? NO! WTF ?? No out of ranges? It should be!
Code: Select all
$stmt -> bind_param("i",$a);
$a = 4294967297;expected? NO! Should be out of range... but the value went over just like in the above example...
Why does it go over? For those "out of range" -values, it won't go over -.-
Rather interesting results...
The prepared statement binding kind of sucks... it allows me to fed up to 2147483647 even though the column is unsigned and accepts up to 4294967295... not nice! If I use strings, like '4294967295', then it won't throw out of range errors, but it will silently convert that to 2147483647 <_<
Has this something to do with http://fi.php.net/manual/en/mysqli-stmt.attr-set.php ? Perhaps it defaults to 2^31 data size for integers by default and requires further actions from me? Still it's odd that integer version throws errors while numerical versions do not.