用PHP变量创建mysql表 [英] Creating a mysql table with a PHP variable
本文介绍了用PHP变量创建mysql表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用PHP变量创建SQL表.
I am having trouble creating a SQL table with a PHP variable.
比方说$ tbl_date =数据";
Let's say $tbl_date = "data";
mysql_query('CREATE TABLE '.$tbl_date.'
(
Test varchar(15),
Yes varchar(15),
Very int
)');
它不会创建表格.
推荐答案
似乎不起作用,因为您的表名不在引号中.试试这个:
It looks like it's not working because your table name is not in the quotes. Try this:
mysql_query('CREATE TABLE `'.$tbl_date.'`
(
`Test` varchar(15),
`Yes` varchar(15),
`Very` int
)');
字段名称也是如此.
也可以尝试一下,这样更容易被人阅读:
And the same applies for field names.
Also try this, it's easier to read by humans:
mysql_query("CREATE TABLE `{$tbl_date}`
(
`Test` varchar(15),
`Yes` varchar(15),
`Very` int
)");
请注意不同类型的引号:
-单引号和双引号用于在PHP中构建某些字符串(例如SQL查询)
-反引号特别用作表名和列名的SQL查询的一部分
Please note different types of quotes:
- single quotes and double quotes for building some string (eg.SQL query) in PHP
- back quotes used specially as a part of SQL query for table names and column names
这篇关于用PHP变量创建mysql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文