php - PDO statement where table and field names are variables -


this question has answer here:

i trying update db using pdo statement, have had no real problems until try update using variables name , field .

    $real_function = 'top' ;     $value = 99 ;     $tablename = "twitter_control" ;      $stmt = $pdo->prepare("update ? set ?=? id='control' ");     $stmt->execute(array( $tablename, $real_function, $value )); 

if use code works expected

  $stmt = $pdo->prepare("update twitter_control set top=? id='control' ");   $stmt->execute(array( $value )); 

how can make work ? , suggestions please ?

you can do:

$stmt = $pdo->prepare("update {$tablename} set {$real_function}=? id='control' "); 

in prepare statement work. far know can bind values execute input parameter or bindparam function.. if can correct me otherwise..

dins


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -