I am trying to accomplish an INSERT statement and one of my fields requires me to pull data from the database and use it in my INSERT statement. For Example.
$stmt = $dbh->prepare("INSERT INTO city(id, cityname, stateID) ".
"VALUES ('NULL', :city, :stID)");
At this point I would bindValue's and execute. However I want to use a select statement to find the value for stID.
SELECT id FROM state WHERE statename=NY
Do I need to save the query in a variable then execute the INSERT statement with the variable or is there a way to add the select statement inside my insert statement using PDO?
I feel this question is not a duplicate because the questions that are referenced as duplicates did not talk about how to accomplish this task using PDO. I was unaware that select statements can be placed directly inside the VALUES parameter.