Jump to content

Create And Copy Table Concatenation Help


BigTime

Recommended Posts

Database one: schedules

Database two: schedulesArchive

 

I need to copy a table named foo from database one to database two and rename it to 2012_foo.

 

$usr = "user";
$pwd = "pass";
$db = "schedules";
$db2 = "schedulesArchive";
$host = "localhost";
# connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }

$year=Date("Y");
SQL = "CREATE TABLE $db2.$year_foo SELECT * FROM $db.foo";
$result = mysql_db_query($db,$SQL,$cid);
# check for error
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

 

My problem is in the naming of the new table I want it to read schedulesArchive.2012_foo, but Im confused on how to get my statement to read the $year parameter inline in my query

 

Thanks in advance

Edited by BigTime
Link to comment
Share on other sites

$usr = "user";
$pwd = "pass";
$db = "schedules";
$db2 = "schedulesArchive";
$host = "localhost";
# connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }


$year=Date("Y");
$db2 = $db2 . $year . "foo";
SQL = "CREATE TABLE $db2 SELECT * FROM $db.foo";
$result = mysql_db_query($db,$SQL,$cid);
# check for error
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.