I have run across a problem. When I use PDO::prepare() to build a certain query, then pass parameters to execute, the query will execute correctly but one of the parameters does not seem to be inserted into the database. The prepare statement looks like this:
... SET col = :par1-:par2 ...
So what I’m trying to do is put the value “[par1]-[par2]” into the column in the database. The problem is that the first parameter is not being stored in the database, but the dash and the second parameter are. So the resulting value being stored in the database from the above query is “-[par2]”.
Why would that be?
What you wrote there is an integer subtraction. So you are writing the result of
par1minuspar2intocol.Instead you should create the string
$par1 . '-' . $par2outside of PDO and then just pass it in via some other named parameter: