OiO.lk Blog SQL using SELECT * INTO to duplicate a record into another database
SQL

using SELECT * INTO to duplicate a record into another database


I am trying to duplicate a table from one database into another database. The original table contains static data. I need to be able to manipulate the data in the ‘copied table’. This process needs to be dynamic as I will be producing multiple copies, one for each user.

At present I am using this code on a PHP call. It is meant to load the relevant data table, select all the data in the table and then create a new table in the player_missions database using the $Player variable as a new table name.

define('HOSTNAME','localhost:3306');  
define('DB_USERNAME','root');  define('DB_PASSWORD','');
define('DB_NAME','geo_locations');  global $conn;
$conn = mysqli_connect(HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_NAME) or die ("error");
  
$Player=$_SESSION["Player_ID"]; $geo_loc="C3B3";

$sql="SELECT * INTO $Player IN 'player_missions.mdb' FROM $geo_loc";

if(mysqli_query($conn, $sql)){} else{echo "ERROR: Was not able to execute $sql. " . mysqli_error($conn);}

As I am sure you can tell, my SQL knowledge is pretty poor but my extended efforts to find a solution have not been fruitful.

This is the error message:

ERROR: Was not able to execute SELECT * INTO 
805361725171703141241123 IN 'player_missions.mdb' FROM C3B3. You
have an error in your SQL syntax; check the manual that 
corresponds to your MariaDB server version for the right syntax 
to use near '805361725171703141241123 IN 'player_missions.mdb' 
FROM C3B3' at line 1

I have visited W3 and other sites but not been able to resolve.



You need to sign in to view this answers

Exit mobile version