Reputation: 630
Hi I am trying to create a table like '$username'_package in google mysql cloud. I could create table successfully but it actually create a table with name like this say '.aaa@gmail.com.'_pakage
but I actually need to create a table with name like aaa@gmail.com_package
.
This my query,
mysql_query("CREATE TABLE `db`.`{$email_append}` (`id` int(25) NOT NULL,`packageid` int(25) NOT NULL,`package_name` varchar(35) NOT NULL,`category` varchar(24) NOT NULL,`description` varchar(24) NOT NULL,`sub_description` varchar(25) NOT NULL,`default_price` int(25) NOT NULL,`custom_price` int(25) NOT NULL,`force_amount` int(25) NOT NULL,`percent_discount` int(25) NOT NULL,`package_total` int(25) NOT NULL)");
These are the try that I have made,
1.'".$username."'
2.'$username'
3.`$username`
4.I created a php variable "$email_append" and concat it with "_package".
Every try gave me the same results. How to solve this. Can someone help me? Thanks in advance.
Upvotes: 0
Views: 43
Reputation: 16117
You can concat like that:
`db`.`{".$email."_append}`
Example:
$email = 'test';
echo "CREATE TABLE `db`.`".$email."_append` (`id` int(25) NOT NULL,`packageid` int(25) NOT NULL,`package_name` varchar(35) NOT NULL,`category` varchar(24) NOT NULL,`description` varchar(24) NOT NULL,`sub_description` varchar(25) NOT NULL,`default_price` int(25) NOT NULL,`custom_price` int(25) NOT NULL,`force_amount` int(25) NOT NULL,`percent_discount` int(25) NOT NULL,`package_total` int(25) NOT NULL)";
Result:
CREATE TABLE `db`.`test_append`
(
`id` INT(25) NOT NULL,
`packageid` INT(25) NOT NULL,
`package_name` VARCHAR(35) NOT NULL,
`category` VARCHAR(24) NOT NULL,
`description` VARCHAR(24) NOT NULL,
`sub_description` VARCHAR(25) NOT NULL,
`default_price` INT(25) NOT NULL,
`custom_price` INT(25) NOT NULL,
`force_amount` INT(25) NOT NULL,
`percent_discount` INT(25) NOT NULL,
`package_total` INT(25) NOT NULL
)
Issue:
In your code {$email_append}
its treated as a full variable, which is not you need to concat $email
and _append
.
Side Note:
Please use mysqli_*
or PDO
instead of mysql_*
its deprecated and not available in PHP 7.
Upvotes: 1