Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when I send boolean True-False to a PDO statement as a parameter which is bound to an int field?

I have an int field in database and :disabled is supposed to be true false, I am assuming database gets boolean values as integer 0 and 1, but I am unsure.

function loadbyinput($name,$password,$ipnumber="0.0.0.0",$type="member",$disabled=FALSE){    
$dbh = new PDO(...);
$statement=$dbh->prepare("insert into 
 actor(name,password,ipnumber,type,disabled)
 values(:name,:password,:ipnumber,:type,:disabled)");
$statement->bindParam(":disabled", $disabled);
}

I am not writing any GUI at the moment so it is hard to test such things for me.

like image 596
Uğur Gümüşhan Avatar asked Dec 05 '11 22:12

Uğur Gümüşhan


2 Answers

The equivalents get passed:

True = 1
False = 0
like image 33
Nonym Avatar answered Nov 13 '22 19:11

Nonym


Depends on your schema. For boolean columns in the database you can use the following construct (there is a BOOLEAN construct, but it's just an alias for TINYINT):

`disabled` tinyint(1) NOT NULL DEFAULT '0'

Then when you bind, you can enforce a bool value:

$stmt->bindValue(':disabled', $disabled, PDO::PARAM_BOOL);
like image 95
Mike Purcell Avatar answered Nov 13 '22 20:11

Mike Purcell