4

I am having a very strange problem inserting values into my mysql database, using php, so i was running a test, the simplest of the simple insert; the following doesnt 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 see what the problem is could I get sum assistance please

4

1 回答 1

3

您不需要在查询中封装表,除非它们有空格或它们是保留字。

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')

如果 trn 列接受数字,它确实应该是:

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

使用 MySQL,您可以使用倾斜的引号字符来封装名称,但不能封装字符串。要在查询中输入字符串,您必须使用普通引号,例如'.

你可以这样做:

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

但不是这个:

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

正确的用法是:

select someTable.someColumn from someTable where myName='Tommy';
于 2012-08-02T12:12:52.770 回答