PHP PDO使用$ variable值作为名称创建表 [英] PHP PDO Create Table using $variable value as name
问题描述
场景:
我们使用查询来创建一个表,如下所示
$ query = ' 创建表xyz'。
' (Id varchar(30),Val varchar(30))';
这里的表名是xyz。我知道表名,所以我能够创建它。在下一种情况下,我不知道表的名称,名称在变量$ TableName中。我现在如何创建表格
$ TableName = xyz; - >计算 运行时
$ query = ' CREATE TABLE'。$ TableName。' '。
' (Id varchar(30),Val varchar(30))';
当我执行表时没有创建。这种格式是否正确?
query = ' CREATE TABLE xyz'。
' (Id varchar(30),Val varchar(30))';
这里的表名是xyz。我知道表名,所以我能够创建它。在下一种情况下,我不知道表的名称,名称在变量
TableName中。我现在如何创建表格
Scenario:
< blockquote> TableName = xyz; - >计算 运行时
TO crate a table we use the query as shown below
$query = 'CREATE TABLE xyz ' .
'(Id varchar(30), Val varchar(30))';
Here the table name is "xyz". I know the table name so i was able to create it. In the next case i do not know the name of the table and the name is in the variable $TableName. How do i create the table now
$TableName = "xyz"; -->Calculated in run time
$query = 'CREATE TABLE '.$TableName.' ' .
'(Id varchar(30), Val varchar(30))';
When i execute the table is not being created. Is this format correct?query
= 'CREATE TABLE xyz ' .
'(Id varchar(30), Val varchar(30))';
Here the table name is "xyz". I know the table name so i was able to create it. In the next case i do not know the name of the table and the name is in the variable
TableName. How do i create the table now
TableName = "xyz"; -->Calculated in run time
这篇关于PHP PDO使用$ variable值作为名称创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!