PDO Error - Syntax error or access violation: 1064

1.2k views Asked by At

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

0

There are 0 answers