Hi all,
I am having a little trouble getting a prepared query to bind boolean paramaters correctly. What I am trying to do is set an 'active' field to either true or false. The mysql field was set up as a BOOLEAN type and shows up in the database description as 'tinyint(1)'. Here is the code that I have for submitting an update:
$sql = "UDPATE contacts SET active=:active WHERE contactsid=:cid";
if (!$sth = $dbo->prepare($sql)) {
// record the error
}
$sth->bindParam(':active', $active, PDO::PARAM_BOOL);
$sth->bindParam(':cid', $contactsid, PDO::PARAM_INT);
if (!$sth->execute()) {
// record the error
}
In the previous code, here are what the variables are all defined as:
$dbo = A valid PDO object.
$active = This gets set either to an int of 0 (false) or 1 (true), since that is how it is defined in the database field.
$contactsid = An integer value representing a valid entry in the database.
The problem is, whenever the bindParam function occurs, it wraps single quotes around the 0/1 value so that my query shows up as the following in the mysql_bin log:
UPDATE contacts SET active='0' WHERE contactsid='1';
When this gets executed, it ALWAYS evaluates this for the BOOLEAN field to be true since it is a non-empty string. Any idea how to make this bind correctly?
Thanks,
Michael