With this code I am duplicating my table row:
$old_name = "Laura";
$new_name = "Sam";
$pdo = $db->prepare('INSERT INTO animals (status, name) SELECT status, name FROM animals WHERE name = :name');
$pdo->execute(array(
':name' => $old_name,
));
It is working well, but I need to put on the position of name
by the new insert a custom value.
This is my approach:
$old_name = "Laura";
$new_name = "Sam";
$pdo = $db->prepare('INSERT INTO animals (status, name) values(:name) SELECT status, name FROM animals WHERE name = :name');
$pdo->execute(array(
':name' => $new_name,
':name' => $old_name,
));
The error message is:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax