0

I have a Query That work in phpmyadmin but not work on php (mysqli)

where is the problem ?

Query:

  INSERT INTO `SepidarSoft_Portal`.`Archive_Media` SET `CTime`='1364135670',`UTime`='1364135670',`PID`='',`State`='1',`Sequence`='0',`Subject`='Hojom Marg ( www.Parstafrih.ir )',`Text`='',`Description`='',`Definition`='',`KeyWord`='',`ETag`='',`Access`='',`LinkToPage`='',`Attachment`='[{\"Name\":null,\"Kind\":null,\"Size\":false,\"Address\":\"27\",\"More\":{\"Original\":1}}]',`STime`='0',`ETime`='0';

  SET @LAST_ID:=LAST_INSERT_ID();

  INSERT INTO `SepidarSoft_Portal`.`Archive_Media_MoreInfo`  (`id`,`Key`,`Value`) VALUES (@LAST_ID,'Instrumental','1'),(@LAST_ID,'KindFile','صوتی'),(@LAST_ID,'Genre','نغمه'),(@LAST_ID,'SName','Amir Tajik ( www.Parstafrih.ir )'),(@LAST_ID,'Events','[[\"\"]]'),(@LAST_ID,'Album','( www.Parstafrih.ir )'),(@LAST_ID,'Composer',''),(@LAST_ID,'Adjustment',''),(@LAST_ID,'Subtitle','[object HTMLInputElement]'),(@LAST_ID,'Release','');

Error:

  #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 'SET @LAST_ID:=LAST_INSERT_ID();

1) I use php mysqli_multi_query for this

Oliver M Grech
  • 3,071
  • 1
  • 21
  • 36
mohammad mohsenipur
  • 3,218
  • 2
  • 17
  • 22

1 Answers1

0

Your issue is simple.

Backticks ( ` ) are used to execute commands in php. That's why you're being given a syntax error. Replace them with single or double quotes within your mysqli functions.

Kindly read the following document and you should be sorted :)

Backticks on php.net

Oliver M Grech
  • 3,071
  • 1
  • 21
  • 36
  • From your link `Note: Unlike some other languages, backticks cannot be used within double-quoted strings.` So `mysqli_multi_query("INSERT INTO \`SepidarSoft_Portal\`.\`Archive_Media\` SET ...")` will not execute a command. It is acceptable to use backticks when your table and/or column name is a MySQL reserved word. see also - http://stackoverflow.com/a/11321508/689579 – Sean Mar 24 '13 at 15:11
  • Also, your suggestion to use `single or double quotes within your mysqli functions` will not work if their MySQL is not in [ANSI mode](http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html) using [ANSI_QUOTES](http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_ansi_quotes), which [MySQL by default has no special modes enabled](http://dev.mysql.com/doc/refman/5.0/en/faqs-sql-modes.html#qandaitem-B-3-1-7). – Sean Mar 24 '13 at 15:20