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

$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"); }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.