0

I have this query:

pg_prepare($conn, 'set_ui_advanced', 'update system.boxes set ui_advanced=$1 where id=$2');

$update_cmd_exec = pg_execute($conn, 'set_ui_advanced', array($ui_advanced, $system));

The column is boolean type.

Whenever I get my variable from the front-end like this:

$ui_advanced = boolval(trim($_POST['ui_advanced']));

I'm passing 0 and 1 and then return the variable and get false, true respectively. So, I've verified that my variables have gone through correctly. However, when passed to the query, my column only updates if the variable was set to 1 and not 0, even though I'm still getting true and false back.

I solved it by just using:

intval($variable) 

instead and letting postgres deal with it, but why wouldn't true AND false work?

I looked HERE to verify that postgres allowed true and false which is how php represents true, false.

DJSweetness
  • 153
  • 1
  • 14

1 Answers1

0

I ran this simple script:

$var = boolval('1');
echo("True: ");
echo($var);
echo(" False: ");               
$var = boolval(0);
echo($var);

From this, the output was:

True: 1 False:

I then looked up why printing False didn't print anything and I was lead to this question:

Why doesn't PHP print TRUE/FALSE?

To sum up answers from this question, the Php Documentation for strings says that when printing true and false, the results above are expected and is stated as:

A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values.

DJSweetness
  • 153
  • 1
  • 14