问题
I'am trying to create table with variable name and columns via forms here's my query
$execute = mysql_query('CREATE TABLE '.$tName.'(
'.$cName.' '.$cType.' )');
And it's creating table with name from variable $tName
but it doesnt create the columns.
回答1:
Try this:
$sql= "CREATE TABLE $tName($cName $cType(45),$cName $cType(50))";
//echo $sql;
$op =mysql_query($sql);
回答2:
OK try this, I think it gives the general idea
<?php
include 'connect-db.php';
$tbl_name='kerry';
$field1='name';
$field2='value';
$field3='date';
mysql_query("CREATE TABLE `{$tbl_name}`
(
$field1 varchar(15),
$field2 int,
$field3 date
)");
?>
来源:https://stackoverflow.com/questions/29634469/creating-table-with-variable-name-php-mysql