When Renaming table name, it is actually dropping table from Mysql - Using PHP

231 Views Asked by At

I am running into a very weird problem in my PHP script when trying to rename my table name. Instead of renaming it, it is dropping it.

Background Info:

  1. I am running the script on my browser
  2. Rename to the original table name happens right after the drop of original table.

Code Example:

$tableSuffix = "1";
$tableSuffix2 = "2";

// This table already exists "testing_$tableSuffix LIKE template_testing"

// This is being created
CREATE TABLE testing_$tableSuffix2 LIKE template_testing

$queryString = "DROP TABLE testing_$tableSuffix";
$query = $db->query($queryString);
    
$queryString = "RENAME TABLE testing_$tableSuffix2 TO testing_$tableSuffix";
$query = $db->query($queryString);

Renaming is not happening and both testing_$tableSuffix and testing_$tableSuffix2 are dropping and getting deleted.

1

There are 1 best solutions below

1
stackbee On

Looks like I figured out the bug. Not sure yet though why it is happening on Chrome only and not Safari. My script is running 2 instances within 2 seconds on Chrome, however this issue does not happen on Safari.