I’m starting out with PDO and trying to replace this code, which works:
$dbh->query("INSERT INTO sugestao (id, fbid, username, latitude, longitude, endereco, categoria, titulo, descricao, foto)
VALUES (null,
'".$fbid."',
'".$username."',
'".$lat."',
'".$lon."',
'".$endereco."',
'".$categoria."',
'".$titulo."',
'".$descricao."',
'".$foto."')");
With this one, that seems safer and better maintainable, and that should also allow me to safely get the last ID inserted:
$dbh->beginTransaction();
$dbh->prepare("INSERT INTO sugestao (id, fbid, username, latitude, longitude, endereco, categoria, titulo, descricao, foto)
VALUES (null, :fbid, :username, :lat, :lon, :endereco, :categoria, :titulo, :descricao, :foto)");
$dbh->bindParam(":fbid", $fbid);
$dbh->bindParam(":username", $username);
$dbh->bindParam(":lat", $lat);
$dbh->bindParam(":lon", $lon);
$dbh->bindParam(":endereco", $endereco);
$dbh->bindParam(":categoria", $categoria);
$dbh->bindParam(":titulo", $titulo);
$dbh->bindParam(":descricao", $descricao);
$dbh->bindParam(":foto", $foto);
$dbh->execute();
$lastid = $dbh->lastInsertId();
$dbh->commit();
This second one, gives me a 500 Server Error. Any clues?
bindParamandexecuteare function from PDOStatement and not from PDO :