最近、Mysqlデータベースをあるエンコーディングから別のエンコーディングに変換するスクリプトを書きました。 その後、クラスを作成してスクリプトを書き直すことにしました。 これで、スクリプトでこのライブラリを接続できます。 このクラスの使用法を以下に示します。
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
-
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v
<?php /** * Mysql */ class convertCharsetDb { protected $_charsetFrom = 'cp1251' ; protected $_charsetTo = 'utf8' ; protected $_isInnoDb = true ; private $__db ; protected $_dbParams = array ( ) ; protected $_logger = array ( ) ; public function __construct ( $charsetFrom , $charsetTo , $host , $user , $password , $dbName ) { $this -> _charsetFrom = $charsetFrom ; $this -> _charsetTo = $charsetTo ; // . $this -> connectToDb ( $host , $user , $password , $dbName ) ; } /** * , , $_charsetTo */ public function convertDb ( ) { if ( false === $this -> __db -> query ( 'SET NAMES ' . $this -> _charsetTo ) ) { $this -> insertLog ( 0 , 'ERROR SET NAMES' ) ; return false ; } // . if ( false === ( $resultSetTables = $this -> __db -> query ( 'SHOW TABLES' ) ) ) { $this -> insertLog ( 0 , 'ERROR SHOW TABLES' ) ; return false ; } if ( $resultSetTables -> num_rows ) { // . while ( $rowSet = $resultSetTables -> fetch_row ( ) ) { if ( ! $this -> changeTableCharset ( $rowSet [ 0 ] ) ) { $this -> insertLog ( 0 , 'ERROR changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } else { $this -> insertLog ( 1 , 'SUCCESS changeTableCharset. Table: ' . $rowSet [ 0 ] ) ; } } } // . $_sql = 'ALTER DATABASE `' . $this -> _dbParams [ 3 ] . '` DEFAULT CHARACTER SET ' . $this -> _charsetTo . ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; if ( false === $this -> __db -> query ( $_sql ) ) { $this -> insertLog ( 0 , 'ERROR CHANGE DATABASE CHARSET. DB: ' . $this -> _dbParams [ 3 ] ) ; } } /** * $tableName . * . , * $tableName. * @param string $tableName * @return bool */ public function changeTableCharset ( $tableName ) { // . if ( false === ( $createTableRes = $this -> __db -> query ( 'SHOW CREATE TABLE ' . $tableName ) ) ) { return false ; } $createTableRow = $createTableRes -> fetch_assoc ( ) ; // . $createTableStr = $createTableRow [ 'Create Table' ] ; // . (). if ( $this -> _isInnoDb ) { $createTableStr = str_replace ( 'ENGINE=MyISAM' , 'ENGINE=InnoDB' , $createTableStr ) ; } // . // , (!) , // $_params['charset_from']. // $_params['charset_to'] $createTableStr = str_replace ( $this -> _charsetFrom , $this -> _charsetTo , $createTableStr ) ; // $createTableStr = str_replace ( 'CREATE TABLE `' . $tableName . '`' , 'CREATE TABLE `' . $tableName . '__tmp`' , $createTableStr ) ; // COLLATE, . $createTableStr .= ' COLLATE ' . $this -> _charsetTo . '_general_ci' ; // . if ( false === $this -> __db -> query ( $createTableStr ) ) { return false ; } // . $resultSetData = $this -> __db -> query ( 'SELECT * FROM ' . $tableName ) ; if ( $resultSetData -> num_rows ) { // . while ( $rowDataSet = $resultSetData -> fetch_assoc ( ) ) { $_sqlVariables = $_sqlValues = array ( ) ; // . foreach ( $rowDataSet as $rowVariable => $rowValue ) { array_push ( $_sqlVariables , $rowVariable ) ; array_push ( $_sqlValues , $rowValue ) ; } // . $_sql = 'INSERT INTO `' . $tableName . '__tmp` (' . implode ( ',' , $_sqlVariables ) . ') VALUES("' . implode ( '" , "' , $_sqlValues ) . '")' ; $this -> __db -> query ( $_sql ) ; } } // . $_sql = 'DROP TABLE `' . $tableName . '`;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } // . $_sql = 'ALTER TABLE `' . $tableName . '__tmp` RENAME `' . $tableName . '` ;' ; if ( false === $this -> __db -> query ( $_sql ) ) { return false ; } return true ; } /** * . * @param string $host * @param string $user * @param string $password * @param string $dbName * @return connector */ public function connectToDb ( $host , $user , $password , $dbName ) { $this -> _dbParams = array ( $host , $user , $password , $dbName ) ; return $this -> __db = new MySQLi ( $host , $user , $password , $dbName ) ; } public function setFromCharset ( $charset ) { $this -> _charsetFrom = $charset ; } public function setToCharset ( $charset ) { $this -> _charsetTo = $charset ; } private function insertLog ( $type = 0 , $message ) { switch ( $type ) { case 1 : if ( ! isset ( $this -> _logger [ 'success' ] ) ) { $this -> _logger [ 'success' ] = array ( ) ; } array_push ( $this -> _logger [ 'success' ] , $message ) ; break ; default : if ( ! isset ( $this -> _logger [ 'error' ] ) ) { $this -> _logger [ 'error' ] = array ( ) ; } array_push ( $this -> _logger [ 'error' ] , $message ) ; break ; } } public function showLog ( ) { echo '--------------------------<br />' ; echo '--------SUCCESS---------<br />' ; if ( count ( $this -> _logger [ 'success' ] ) ) foreach ( $this -> _logger [ 'success' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } echo '--------------------------<br />' ; echo '--------ERRORS---------<br />' ; if ( count ( $this -> _logger [ 'error' ] ) ) foreach ( $this -> _logger [ 'error' ] as $i => $message ) { echo ( $i + 1 ) . '. ' . $message . '<br />' ; } } li style="font-weight: normal; v