I have been going over this query repeatedly trying to understand why it won't work as a prepared statement when run in PDO, but seems to work fine when set up as a stored procedure. Can anyone help provide some insight into where I may be running in to trouble?
Here is the relevant PHP:
try {
$pdo = new PDO($dbConn,$dbUser,$dbPass);
} catch (PDOException $e){
echo 'Connection failed: ' . $e->getMessage();
}
$statement = 'INSERT INTO dashboard.dashboard (studyName, respondent_id1, respondent_id2, respondent_id3, sample_provider, completion_status, loi, [endpoint]) VALUES (:studyName, :respondent_id1, :respondent_id2, :respondent_id3, :sample_provider, :completion_status, :loi, :ep);';
$result = $pdo->prepare($statement);
$arr = array('studyName' => $studyName, 'respondent_id1' => $respondent_id1, 'respondent_id2' => $respondent_id2, 'respondent_id3' => $respondent_id3, 'sample_provider' => $sample_provider, 'completion_status' => $completion_status, 'loi' => $loi, 'ep' => $endpoint);
$result->execute($arr);
I know I am not having issues with the database connection, as the query works with hard-coded values, just not with a prepared statement.
For reference, if I replace $statement with the following it works fine:
$statement = "INSERT INTO dashboard.dashboard (studyName, respondent_id1, respondent_id2, respondent_id3, sample_provider, completion_status, loi, [endpoint]) VALUES ('testingNewPush', 'test', 'test', 'test', 'provEx', 'terminate', 500, 'testing');";
In addition, I am receiving the following output when I var_dump($arr):
array(8) { ["studyName"]=> NULL ["respondent_id1"]=> string(5) "test2" ["respondent_id2"]=> string(4) "test" ["respondent_id3"]=> string(4) "test" ["sample_provider"]=> string(10) "Communicus" ["completion_status"]=> string(9) "terminate" ["loi"]=> int(600) ["ep"]=> string(3) "Age" }
I would really appreciate any insight into what I may be doing wrong here.