Advertisement
gitlez

YA: MySQL Collation Changed With PHP

Sep 16th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2. $DB_HOST = 'localhost'; // The host or domain to your MySQL database
  3. $DB_NAME = 'my_database'; // The database containing the Tables you wish to change.
  4. $DB_USER = 'root'; // The Username that has privilages or access to the database
  5. $DB_PASS = 'password'; // The password associated with the username
  6.  
  7.  
  8. $db = mysql_connect($DB_HOST, $DB_USER, $DB_PASS) or die('Couldn\'t Connect to MySQL. Please recheck the Host, Username and Password');
  9. mysql_select_db($DB_NAME) or die('Couldn\'t Connect to the Database. Please double check the name of the database for typos. As well as ensure that the Username has privilages on the database');
  10. $r = mysql_query('SHOW TABLES');
  11. while($t= mysql_fetch_array($r)){
  12.     foreach($t as $k => $v) {
  13.         mysql_query("ALTER TABLE $value COLLATE latin1_swedish_ci") or die('MySQL Query Error: ' . mysql_error());
  14.     }
  15. }
  16. echo 'All Tables in database, have successfully been altered.';
  17. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement