BigTime Posted December 20, 2012 Share Posted December 20, 2012 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 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"); } 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 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! 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
Archived
This topic is now archived and is closed to further replies.