2

Hey guys i want to use an php variable as a part of a name of a mysql table which i create with a query. I used two types of quotes like a example i saw on the internet. It should create an individual table name. $cn is not an array it is an single value. I have php error reporting enabled and it doesn't show any errors. Here is what i tried:

$sql2 = "CREATE TABLE lm_Warenkorb_`".$cn."`
     (
     Index TEXT,
     )";

Why isn't this working? Is this possible or not? Hope it is clear what i want to do.

4

3 回答 3

3
$sql2 = "CREATE TABLE `lm_Warenkorb_".$cn."`
     (
     Index TEXT,
     )";
于 2012-11-29T11:22:38.500 回答
2

我认为您需要将整个表名包含在反引号中...

$sql2 = "CREATE TABLE `lm_Warenkorb_{$cn}`
     (
     Index TEXT,
     )";

您也可以使用大括号将变量插入用双引号封装的字符串中。

于 2012-11-29T11:22:37.453 回答
2

您的代码将生成字符串:

CREATE TABLE lm_Warenkorb_`some_string`(Index TEXT,)

我认为它必须是2个变种:

CREATE TABLE `lm_Warenkorb_`.`some_string`(Index TEXT,)

或者

CREATE TABLE `lm_Warenkorb_some_string`(Index TEXT,)
于 2012-11-29T11:23:08.427 回答