Automatically fix lower case table names in SilverStripe


/ Published in: PHP
Save to your folder(s)

This code should be inserted into /sapphire/core/model/MySQLDatabase.php at line 399 (after the if statment ends and before the user_error call)

Be sure to replace 'database_name' with, well you know...

When I used this I first loaded the home page. This fixed a large number of the tables, then ran /dev/build and that fixed the rest.


Copy this code and paste it in your HTML
  1. $dbname = 'database_name';
  2. preg_match("/Table '".$dbName."\.(.*)' doesn't exist/",$matches[2],$tables);
  3. if(isset($tables[1]) && $tables[1] == true)
  4. {
  5. $sql = 'RENAME TABLE '.strtolower($tables[1]).' TO '.$tables[1].';';
  6. mysql_query($sql);
  7. echo "<script type=\"text/javascript\" language=\"JavaScript\">window.location.reload();</script>";
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.