-3

Could someone tell me what I am doing wrong.

If I use the code below, I am able to update the DB.

            $sUpdateSql = "UPDATE googleAnalytics SET $period = '$value' WHERE statisticName = '$item' ";
            $preparedStatement = $db->query($sUpdateSql);

However, with the statement below the DB does not update.

            $sUpdateSql = "UPDATE googleAnalytics SET $period = '?' WHERE statisticName = '?' ";
            $preparedStatement = $db->prepare($sUpdateSql);
            /* bind parameters for markers */
            $preparedStatement->bindValue(1, $value);
            $preparedStatement->bindValue(2, $item);
            $preparedStatement->execute();
tadalendas
  • 1,461
  • 3
  • 16
  • 37

1 Answers1

3

Remove the single quotes around the question marks.

bindValue handles escaping the strings.

Just an FYI, you can also name your params.

"SELECT * FROM foo WHERE id = :id"

bindValue('id', $id);
MajorCaiger
  • 1,893
  • 1
  • 12
  • 18