I have a problem and I don't know what it may be, in principle I think I'm doing well but it doesn't insert the data in the database correctly. Instead of inserting the data, what it does is to name the references. What am I doing wrong? Thanks in advance
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
$fecha='2018-03-06';
$idoriginal=45646546;
$tcin='09:38:00';
$loca='\\\\prueba\fsdfsdf';
$con = "INSERT INTO registros_tempo (id, fecha, id_original, tc_in, ta_vt)"
. " VALUES (NULL, ':fecha', ':id_original', ':tc_in', ':loca');";
// Prepare the sql statement.
$consulta=Conexion::conectar()->prepare($con);
// Bind the input parameters to the prepared statement.
//$consulta->prepare($con);
$consulta->bindParam(":fecha", $fecha, PDO::PARAM_STR);
$consulta->bindParam(":id_original", $idoriginal, PDO::PARAM_INT);
$consulta->bindParam(":tc_in", $tcin, PDO::PARAM_STR);
$consulta->bindParam(":loca", $loca, PDO::PARAM_STR);
//$consulta = $consulta->prepare($con);
$executar = $consulta->execute();
$consulta->setFetchMode(PDO::FETCH_ASSOC);
$ultimoIdInsertado = Conexion::conectar()->lastInsertId();
// Display last insert id.
echo 'Registro añadido con id ' . $ultimoIdInsertado;
// Close connection.
$consulta = NULL;
} catch (PDOException $exc) {
echo $exc->getMessage();
exit();
} catch (Exception $exc) {
echo $exc->getMessage();
exit();
}
When I insert in the db instead of appearing...:
01 2018-03-06 45646546 \\prueba\fsdfsdf
I'm getting this other one...:
01 0000-00-00 0 :loca
What am I doing wrong?
Thanks in advance
/////////////////////////////////////////////// SOLUTION Indeed, I was doing something wrong, now if the references happen to me correctly... I don't have to add quotation marks in the references in the consultation of the prepared sentence.
/////////////////////////////////