I am having a little trouble saving bit-values into my PostgreSQL-DB using PDO. Whenever the bit(bool) is false i get this error
Warning: PDOStatement::execute(): SQLSTATE[22026]: String data, length mismatch: 7
ERROR: bit string length 0 does not match type bit(1) in /var/www/html/application/models/Database.php on line 75
The code is a little complicated to show, but here is what goes into the DB-class.
UPDATE users SET name=:name,email=:email,address=:address,zip=:zip,joindate=:joindate,phone=:phone,password=:password,activationcode=:activationcode,birthdate=:birthdate,lastdigits=:lastdigits,driverlicense=:driverlicense,e_presentation=:e_presentation,e_showphone=:e_showphone,e_showaddress=:e_showaddress,e_radius=:e_radius,e_showinsearch=:e_showinsearch,w_presentation=:w_presentation,w_showphone=:w_showphone,w_showaddress=:w_showaddress,w_radius=:w_radius,w_showinsearch=:w_showinsearch WHERE id=:id
And the data that is bound to the parameters
Array ( [:name] => My Name [:email] => myemail@gmail.com [:address] => My Address [:zip] => 79133 [:joindate] => 2012-09-18 12:39:56.769584 [:phone] => 073 917 13 97 [:password] => c6d18ac44b378ff3cecf09d9ebec31ad301c4394d7e1sdfjksc81cd3fbf47777f8df0ac9f33d14da18d71b76fc9c3e1210cb2efcabf6ed66f779d [:activationcode] => [:birthdate] => 1993-08-05 [:lastdigits] => 5079 [:driverlicense] => 0 [:e_presentation] => Test [:e_showphone] => 1 [:e_showaddress] => 1 [:e_radius] => 10 [:e_showinsearch] => 1 [:w_presentation] => Test [:w_showphone] => 1 [:w_showaddress] => 1 [:w_radius] => 10 [:w_showinsearch] => 1 [:id] => 28 ) 1
A quick Google-search shows me that others had the same problem, but no solution to it.
If we consider that a bit is a number that is either 1 or 0, then
falsein php is not a number.<? echo false; ?>prints an empty string, not the number0.In a lot of other situations in php,
0andfalsewill be equivalent, but they’re still not the same thing, and from the point of view of PostgreSQL, an empty string as the value of a bit is not acceptable.The php code should convert
falseto0when passing the bit value toexecute()or similar.Using
would also work when
$valueisfalse, since that would force a conversion to0.