BigTime Posted December 20, 2012 Share Posted December 20, 2012 (edited) 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 December 20, 2012 by BigTime Quote Link to comment https://forums.phpfreaks.com/topic/272207-create-and-copy-table-concatenation-help/ Share on other sites More sharing options...
twistedvengeance Posted December 20, 2012 Share Posted December 20, 2012 $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"); } Quote Link to comment https://forums.phpfreaks.com/topic/272207-create-and-copy-table-concatenation-help/#findComment-1400529 Share on other sites More sharing options...
BigTime Posted December 20, 2012 Author Share Posted December 20, 2012 I'll give it a try thanks for your time Quote Link to comment https://forums.phpfreaks.com/topic/272207-create-and-copy-table-concatenation-help/#findComment-1400531 Share on other sites More sharing options...
BigTime Posted December 20, 2012 Author Share Posted December 20, 2012 slight modification: $db2 = $db2 . $year . "foo"; to $db2 = $db2 . "." . $year . "_foo"; Got me to where I wanted to be. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/272207-create-and-copy-table-concatenation-help/#findComment-1400536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.