Data is not inserted into mysql database due to differences in 'quotes'

I have a very strange problem inserting values โ€‹โ€‹into my mysql database using php, so I ran a test, the easiest of simple insertion; The following does not work:

<?php include("config.php"); // put the *FULL* path to the file. mysql_query("INSERT INTO 'lms'.'test2' ('trn') VALUES ('17')"); ?> 

However, the following works: (Note the difference in single quotes)

 <?php include("config.php"); // put the *FULL* path to the file. mysql_query("INSERT INTO `lms`.`test2` (`trn`) VALUES ('17')"); ?> 

I really canโ€™t understand what the problem is, can I get help in the amount of

+4
source share
1 answer

You do not need to encapsulate the tables in the query if they do not have space or are reserved.

 INSERT INTO 'lms'.'test2' ('trn') VALUES ('17') // This makes no real sense to the db. It should be: INSERT INTO lms.test2 (trn) VALUES ('17') 

If the trn column accepts numbers, it really should be:

 INSERT INTO lms.test2 (trn) VALUES (17) 

In MySQL, you can use the oblique quote character to encapsulate names, but not strings. To enter a string in a query, you will need to use regular quotation marks, such as ' .

You can:

 select `someTable`.`someColumn` from `someTable` 

but not this:

 select someTable.someColumn from someTable where myName=`Tommy`; 

Proper use:

 select someTable.someColumn from someTable where myName='Tommy'; 
+3
source

All Articles