小编典典
BIT列是mysql中的二进制类型(尽管它记录为数值类型-
并非完全正确),我建议避免由于客户端库问题(PDO问题证明)而避免使用它。如果将列的类型修改为TINYINT(1),您将省去很多麻烦
当然,TINYINT(1)将消耗每一行的完整字节存储空间,但是根据mysql docs BIT(1)也会这样做。
来自:http :
//dev.mysql.com/doc/refman/5.1/en/storage-
requirements.html
位存储要求是:大约(M + 7)/ 8字节,这表明BIT(M)列也是字节对齐的。
我也发现了这个:https :
//bugs.php.net/bug.php?id=50757
因此,您可以检查以下代码是否按预期工作:
$pdo = new PDO("connection string etc") ;
$statement = $pdo->prepare('INSERT INTO `test` (SomeText,TestBool) VALUES (:someText,:testBool)') ;
$statement->bindValue(':someText', "TEST");
$statement->bindValue(':testBool', 0, PDO::PARAM_INT);
$statement->execute();
您也可以尝试使用与PARAM_INT不同的类型提示,即使您可以使用,我还是建议您改用TINYINT。
2020-05-17