I am trying to make an insert in a table from php PDO and I have some problems since I am trying to use a select and another data at the same time.
$stmt = $db->prepare("INSERT INTO subscriptions(id_Event,pushToken,os)
:idOfEvent, (Select pushToken,os FROM users WHERE deviceUDID = :deviceUDID)");
$stmt->execute(array(':deviceUDID' => $deviceUDID,':idOfEvent' => $idOfEvent));
But it says that I have a problem in my query. I don't know how to make an insert using selects and data at the same time.
The problem is in the SQL query syntax, which is wrong. Try this:
$stmt = $db->prepare("INSERT INTO subscriptions (id_Event, pushToken, os)
SELECT :idOfEvent, pushToken, os
FROM users
WHERE deviceUDID = :deviceUDID");
$stmt->execute(array(':idOfEvent' => $idOfEvent,
':deviceUDID' => $deviceUDID ));
EDIT: Wrapped the query in your PHP code, just to be clear about the PDO parameters.