-1

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.

BrianB
  • 411
  • 1
  • 4
  • 11
  • 1
    The error occurs before the code you posted. As you said, probably a missing semicolon. Start from the line mentioned in the code and work backwards a line or so from there. – Mike Mar 31 '17 at 04:21
  • Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Masivuye Cokile Mar 31 '17 at 09:13

1 Answers1

1

I think the only problem in this code is line:

$array - array('Black Duffle Bag');

It must be:

$array = array('Black Duffle Bag');

I tried your code with modify above and it works with no error!

Sang Lu
  • 308
  • 3
  • 10
  • Interesting that when you changed the hyphen to = (which was clearly an error in my code) that it works on your system. After you pointed this out I tried it on mine and it still fails with the same error. Makes me wonder if there is some ini file or other set up that needs to be tweaked. – BrianB Mar 31 '17 at 18:24