mysql - pdo binding parameters in loop -


i have following sql statement:

$sql = "update houses set title=:title "; 

which dynamically edit according object "location", have several paramaters (some of them null, thefore omitted)

//are there location parameters need added query? if (isset($house->location)){     //go through them , add them query     foreach ($house->location $key=>$locationparameter) {          $sql.=','.$key.'=:'.$key;         }      //finish query      $sql.=" id=:id";      $stmt = $db->prepare($sql);        //bind defined location parameters query          foreach ($house->location $key=>$locationparameter) {          $stmt->bindparam($key, $locationparameter);         }      } else {              //there none location parameters, prepare original query title , id              $sql.=" id=:id";              $stmt = $db->prepare($sql);           } //and bind required parameters       $stmt->bindparam("title", $house->title); $stmt->bindparam("id", $id); $stmt->execute(); 

when echoed query (echo $sql) looked want , binded parameters right, when run query database columns location parameters updated last value location object, example:

 $house->location->lat 25.5  $house->location->lon 28.755  $house->location->city munich 

after execution of query object, columns in db lat, lon, , city filled "munich". tell me, doing wrong?

+var_dump($sql) ->

string 'update houses set title=:title,lat=:lat,lon=:lon,city=:city id=:id' 

without reading entire question though, caught eye

the columns in db lat, lon, , city filled "munich".

quoting pdo tag wiki:

if don't know if need bindvalue() or bindparam(), go former. bindvalue() less ambiguous , has lesser side effects.

most cause.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -