Before I insert a row, I want to check for its existence, in order to avoid duplicates.
So, I
$pdo = ConenctToDatabase();
// Check for existence - don't add a duplicate
$sqlQuery = $pdo->prepare('SELECT campaign_id FROM campaigns WHERE (customer_id=:$customerId) AND (title=:campaignTitle) AND (description=:campaignDescription) AND (start_time=:startTimeStamp) AND (end_time=:endTimeStamp)');
$sqlQuery->bindParam(':customerId', $customerId, PDO::PARAM_INT);
$sqlQuery->bindParam(':campaignTitle', $campaignTitle);
$sqlQuery->bindParam(':campaignDescription', $campaignDescription);
$sqlQuery->bindParam(':startTimeStamp', $campaignTitle);
$sqlQuery->bindParam(':endTimeStamp', $endTimeStamp);
If it doesn't already exist, I want to reuse the PDO statement, changing the SELECT to an INSERT.
The INSERT takes identical parameters. Do I have to bind them again after the second prepare
?
In fact, if you only tried it yourself, you would find that there is no way to change a query in a statement. So, your assumption will fail even with making a "slight modification" to the query, not even making to the stage of "rebinding" values. There is no "second prepare" either. By calling prepare, you are creating a brand new statement that knows nothing of the others (a behavior is common for any other variable in PHP).