1

Really struggling with these damn syntax errors. If anyone can see what's wrong with this please tell me:

Query string

INSERT INTO Categories (ParentId,Title,Desc) VALUES (?,?,?)

Print_R of array passed

Array
(
    [0] => 1
    [1] => Lolcats
    [2] => an entire category dedicated to the language, lolcats!
)

Error:

<b>Fatal error</b>:  Uncaught exception 'PDOException' with message '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 'Desc) VALUES ('1','Lolcats','an entire category dedicated to the language, lolca' at line 1' in /usr/www/maxtingle/Blog/System/Core/Functions.php:168
Stack trace:
#0 /usr/www/maxtingle/Blog/System/Core/Functions.php(168): PDOStatement-&gt;execute(Array)
#1 /usr/www/maxtingle/Blog/System/Core/Category.php(12): Functions\Database-&gt;Insert('(ParentId,Title...', 3, Array)
#2 /usr/www/maxtingle/Blog/System/Category.php(9): Categories::CreateCategory(Object(CategoryIns))
#3 [internal function]: Category::Create()
#4 /usr/www/maxtingle/Blog/index.php(52): call_user_func_array(Array, Array)
#5 {main}
  thrown in <b>/usr/www/maxtingle/Blog/System/Core/Functions.php</b> on line <b>168</b><br>

2 Answers 2

4

Desc is a keyword.To use it as column name use backticks

INSERT INTO Categories (ParentId,Title,`Desc`) VALUES (?,?,?)
Sign up to request clarification or add additional context in comments.

Comments

4

The best practice is to use back ticks for all table names and column names so you will never run into keyword issues.

INSERT INTO `Categories` (`ParentId`,`Title`,`Desc`) VALUES (?,?,?)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.