0

I am trying to run a query but it looks like I am conflicting with a reserved keyword. I can't figure out where the conflict is. I am relatively new to this, so any help would be appreciated.

I have already tried changing all 'row' to 'my_row' - it didn't seem to make a difference.

My code:

        $substmt = $pdo->prepare('  SELECT 
                                        `sentences_index`.`row_id` AS id,
                                        `sentences_index`.`id` AS char_id,
                                        `sentences_index`.`word`,
                                        `definitions`.`pinyin`,
                                        `definitions`.`def1` AS definition,                             
                                        `sentences`.`sentenceEN`

                                    FROM `sentences_index` 
                                    LEFT JOIN `definitions` ON `sentences_index`.`word` = `definitions`.`traditional`
                                    LEFT JOIN `sentences` ON `sentences_index`.`row_id` = `sentences`.`id`

                                    WHERE `sentences_index`.`row_id` = :row 

                                    GROUP BY `sentences_index`.`word`
                                    ORDER BY char_id ASC
                            ');
        $substmt->execute(['row' => $row]);

Any help would be appreciated.

Edit: Here is the error message:

Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS id, sentences_index.id AS char_id, definitions.`p' at line 17 in /var/www/html/assets/other/custom_functions.php:520 Stack trace: #0 /var/www/html/assets/other/custom_functions.php(520): PDO->prepare('\tSELECT \n\t\t\t\t\t\t...') #1 /var/www/html/index.php(216): gc_get_example_sentences(Object(PDO), '\xE8\xAF\xB4\xE8\xAF\x9D', 'simplified') #2 {main} thrown in /var/www/html/assets/other/custom_functions.php on line 520

And I do understand there is a similar question. I have read it and tried to find the same problem in my code. I cannot find the problem, which is why I am asking this question.

Edit2: Interestingly, this error is not thrown in PHP 7.0.0 but is thrown in PHP 7.0.8

Daniel
  • 433
  • 1
  • 3
  • 18
  • Seeing the Whole and Complete error message is far more useful than a summary of one. Including the line number – RiggsFolly Jan 05 '17 at 00:35
  • I don't see any keywords and all your identifiers are quoted. Setup your `$pdo` object to throw exceptions and you'll get back a full error message. `$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);` – Michael Berkowski Jan 05 '17 at 00:36
  • You should at least figure out which query is causing the problem before posting the question. – Gordon Linoff Jan 05 '17 at 00:42
  • Don't use "type" it's reserved. http://dev.mysql.com/doc/refman/5.7/en/keywords.html – AbsoluteƵERØ Jan 05 '17 at 00:46
  • Possible duplicate of [SQLSTATE\[42000\]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO](http://stackoverflow.com/questions/4544051/sqlstate42000-syntax-error-or-access-violation-1064-you-have-an-error-in-you) – AbsoluteƵERØ Jan 05 '17 at 00:47
  • Thanks everybody, I have updated this question with more information. – Daniel Jan 05 '17 at 02:18

0 Answers0