JackWill
JackWill

Reputation: 53

How to execute mysql code with semicolon in php?

The code is

INSERT INTO `semicolon` VALUES ('1', 'a:1:{s:4:\"size\"';\s:2:\"24\";\}'); 

As you might see in double single quotes there is ; (semicolon) and it splits the code because it's the execution sign.

I get an syntax error message otherwise without ; (semicolon) it works fine. If use software like phpmyadmin or navicat it works even with the semicolon.

The question is how to fix it to run within PHP file?

Upvotes: 2

Views: 2800

Answers (2)

GoldenNewby
GoldenNewby

Reputation: 4452

It is due to your single quote, not your semicolon:

INSERT INTO semicolon VALUES ('1', 'a:1:{s:4:\"size\"';\s:2:\"24\";}'); 
-----------------------------------------------------^

Upvotes: 8

juergen d
juergen d

Reputation: 204766

Actually ' is splitting the code. Escape it with \'

 INSERT INTO semicolon VALUES ('1', 'a:1:{s:4:\"size\"\';\s:2:\"24\";}');

' is a string delimiter in SQL. The SQL engine things the string ends with the '.

Upvotes: 6

Related Questions