Is it possible in pdo to have a query with a operator like + - * or / ?
The solution is to put spaces between the ? and the operators this will not work
$table01.Amount - ?*?
This works
$table01.Amount - ? * ?
the query
UPDATE account SET account.Amount = account.Amount - 1000000*0.03 WHERE account.Id = 23;
throws an error but putting this query into the database clients gives me no error
$sqlAccountUpdate="UPDATE $table01
SET
$table01.Amount = $table01.Amount - ?*?
WHERE
$table01.Id = ?;";
try
{
$stmtAccountUpdate = $pdo->prepare($sqlAccountUpdate);
$stmtAccountUpdate->execute([$_POST['new_account_initial_deposit'], $deposit_fee, $accountid]);
}
catch(Exception $e)
{
echo 'Exception -> ';
var_dump($e->getMessage());
}
the error I get is caused by this this is the line that gives the error:
$table01.Amount - ?*?
I know I can work around it by calculating the values before the prepared statement and using 1 variable instead of doing the calculation in the prepared statement.
this works
$initalFee=$_POST['new_account_initial_deposit']*$deposit_fee;
$sqlAccountUpdate="UPDATE $table01
SET
$table01.Amount = $table01.Amount - ?
WHERE
$table01.Id = ?;";
try
{
$stmtAccountUpdate = $pdo->prepare($sqlAccountUpdate);
$stmtAccountUpdate->execute([$initalFee, $accountid]);
}
catch(Exception $e)
{
echo 'Exception -> ';
var_dump($e->getMessage());
}