I can perform the following PDO query successfully:
$db = new PDO('mysql:host=' .DB_HOST.';dbname=' .DB_NAME. '', DB_USER, DB_PASSWORD);
$query = "SELECT ITEM_ID, LISTING_TITLE, PURCHASE_AMT FROM INVNTRY.ITEM WHERE ITEM_ID IN (1,2);";
$result = $db->query($query);
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
echo $row['LISTING_TITLE'];
}
Then close the cursor and db connection.
I mainly showed the above code to illustrate that my database connection is successful:
When I execute this code I get an error on the "prepare" line:
$db = new PDO('mysql:host=' .DB_HOST.';dbname=' .DB_NAME. '', DB_USER, DB_PASSWORD);
$query = $db->prepare('SELECT ITEM_ID, LISTING_TITLE, PURCHASE_AMT FROM INVNTRY.ITEM WHERE LISTING_TITLE = ?');
$array - array('Black Duffle Bag');
$query->execute($array);
$fetch = $query->fetch();
The error is:
Parse error: syntax error, unexpected '$db' (T_VARIABLE)
I know this is normally due to a missing ; or something similar, but I think I have this coded correctly. Is there any configuration file setting required prior to performing a prepare? I am running this second code base on the same instance as the first.