Ho risolto.
In questo modo :
Codice PHP:
$FNpdo->beginTransaction(); // apro transazione /*aggiungo record su fatture*/ try { $sql = 'select * from utenti where ut_id=29' ; $result = $pdo->query($sql); foreach ($result as $res): echo "<br> "; endforeach; } catch (PDOException $e) { $error = 'Error adding Fatture: ' . $e->getMessage(); echo "<script type=\"text/javascript\">alert(\"".$error."\");</script>"; } $insData = array_unique($res); unset($insData['ut_id']); $prep = array();
foreach($insData as $k => $v ) { $prep[':'.$k] = $v;
} $sth = $FNpdo->prepare("INSERT INTO utenti ( " . implode(', ',array_keys($insData)) . ") VALUES (" . implode(', ',array_keys($prep)) . ")"); try { $res = $sth->execute($prep); } catch (PDOException $e) { $error = 'Error adding Fatture: ' . $e->getMessage(); echo "<script type=\"text/javascript\">alert(\"".$error."\");</script>"; } $FNpdo->commit(); // chiudo transazione