PHP PDO使用$ variable值作为名称创建表 [英] PHP PDO Create Table using $variable value as name

查看:69
本文介绍了PHP PDO使用$ variable值作为名称创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:



我们使用查询来创建一个表,如下所示



  $ 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中。我现在如何创建表格



  


< blockquote> TableName = xyz; - >计算 运行时


Scenario:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆