Mysqlベースのエンコーディングを変換するためのPHPクラス

最近、Mysqlデータベースをあるエンコーディングから別のエンコーディングに変換するスクリプトを書きました。 その後、クラスを作成してスクリプトを書き直すことにしました。 これで、スクリプトでこのライブラリを接続できます。 このクラスの使用法を以下に示します。





  1. <?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



  2. <?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



  3. <?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



  4. <?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



  5. <?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



  6. <?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



  7. <?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



  8. <?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



  9. <?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



  10. <?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



  11. <?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



  12. <?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



  13. <?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



  14. <?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



  15. <?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



  16. <?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



  17. <?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



  18. <?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



  19. <?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



  20. <?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



  21. <?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



  22. <?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



  23. <?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



  24. <?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



  25. <?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



  26. <?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



  27. <?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



  28. <?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



  29. <?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



  30. <?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



  31. <?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



  32. <?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



  33. <?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



  34. <?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



  35. <?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



  36. <?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



  37. <?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



  38. <?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



  39. <?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



  40. <?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



  41. <?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



  42. <?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



  43. <?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



  44. <?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



  45. <?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



  46. <?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



  47. <?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



  48. <?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



  49. <?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



  50. <?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



  51. <?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



  52. <?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



  53. <?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



  54. <?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



  55. <?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



  56. <?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



  57. <?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



  58. <?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



  59. <?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



  60. <?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



  61. <?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



  62. <?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



  63. <?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



  64. <?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



  65. <?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



  66. <?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



  67. <?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



  68. <?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



  69. <?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



  70. <?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



  71. <?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



  72. <?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



  73. <?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



  74. <?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



  75. <?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



  76. <?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



  77. <?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



  78. <?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



  79. <?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



  80. <?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



  81. <?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



  82. <?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



  83. <?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



  84. <?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



  85. <?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



  86. <?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



  87. <?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



  88. <?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



  89. <?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



  90. <?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



  91. <?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



  92. <?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



  93. <?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



  94. <?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



  95. <?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



  96. <?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



  97. <?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



  98. <?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



  99. <?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



  100. <?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



  101. <?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



  102. <?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



  103. <?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



  104. <?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



  105. <?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



  106. <?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



  107. <?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



  108. <?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



  109. <?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



  110. <?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



  111. <?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



  112. <?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



  113. <?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



  114. <?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



  115. <?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



  116. <?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



  117. <?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



  118. <?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



  119. <?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



  120. <?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



  121. <?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



  122. <?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



  123. <?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



  124. <?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



  125. <?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



  126. <?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



  127. <?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



  128. <?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



  129. <?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



  130. <?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



  131. <?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



  132. <?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



  133. <?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



  134. <?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



  135. <?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



  136. <?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



  137. <?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



  138. <?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



  139. <?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



  140. <?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



  141. <?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



  142. <?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



  143. <?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



  144. <?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



  145. <?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



  146. <?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



  147. <?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



  148. <?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



  149. <?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



  150. <?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



  151. <?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



  152. <?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



  153. <?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



  154. <?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



  155. <?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






All Articles