Support » Plugin: Utf8ize » Blank screen instead of the SQL statements

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Presslabs

    (@presslabs)

    This is because the functions utf8ize_generator has some error and not execute well. https://github.com/PressLabs/utf8ize/blob/master/utf8ize.php#L145

    Can you check the error log file in order to figure out what is the error?

    • This reply was modified 7 years, 6 months ago by Presslabs.
    Thread Starter mll

    (@mll)

    Sure, but what error log file ? Apache’s ? I’m on a shared host so I’m afaraid I don’t have access to this.

    • This reply was modified 7 years, 6 months ago by mll.
    Plugin Author Presslabs

    (@presslabs)

    Then you can try yo find out what is wrong by using the die, print_r, serialize, var_dump functions starting with line https://github.com/PressLabs/utf8ize/blob/master/utf8ize.php#L25 Just use something like this die( print_r( $your_debug_var, true ) ); where your_debug_var is $db_collate and so on, for every line of the function.

    Thread Starter mll

    (@mll)

    Well, this is at the very limit of my limited skills.

    I tried :

    	function mysql_get_results( $query, $die_on_error = true ) { die( print_r( $db_collate, true ) ); 
    		$result = mysql_query( $query ); die( print_r( $query, true ) ); die( print_r( $result, true ) ); 

    But the page doesn’t display anything more, and the html code still finishes as such :

    <textarea cols=”100″ rows=”20″>

    Plugin Author Presslabs

    (@presslabs)

    Then you can try another method to debug like this:
    – install two plugins: Debug Bar & Debug Bar Console;
    – copy-paste the function utf8ize_generator into the console of the Debug Bar Console plugin;
    – use return ‘message:’.time(); in order to find out where the function breaks like inserting “return ‘message:’.time();” starting with the line https://github.com/PressLabs/utf8ize/blob/master/utf8ize.php#L20 and echo the returned message of the function like in the attached printscreen. https://i.imgsafe.org/257665ae38.png https://i.imgsafe.org/2576726cc4.png

    Thread Starter mll

    (@mll)

    Thanks for your detailed instructions.

    So, I put the following in the debug console :

    <?php
    
    echo 'hello world '.time();
    
    function utf8ize_generator() {
    	return 'message:'.time();
    	mysql_connect( DB_HOST, DB_USER, DB_PASSWORD ) or die( 'Could not connect: ' . mysql_error() );
    	mysql_set_charset( DB_CHARSET ) or die( 'Could not set charset: ' . mysql_error() );
    	mysql_select_db( DB_NAME ) or die( 'Could not select database: ' . mysql_error() );
    
    	$db_collate = ( ! defined( 'DB_COLLATE' ) || '' == DB_COLLATE ? 'utf8_unicode_ci' : DB_COLLATE );
    
    	function mysql_get_results( $query, $die_on_error = true ) { die( print_r( $db_collate, true ) ); 
    		$result = mysql_query( $query ); die( print_r( $query, true ) ); die( print_r( $result, true ) ); 
    		if ( false === $result ) {
    			echo "Error on query: $query\n";
    			echo "\t" . mysql_error();
    			echo "\n";
    			if ( $die_on_error ) {
    				exit(1);
    			}
    		}
    		if ( true === $result ) {
    			return true;
    		}
    		$_ret = array();
    		while ( $row = mysql_fetch_assoc( $result ) ) {
    			$_ret[] = $row;
    		}
    
    		return $_ret;
    	}
    
    	$statements = array( 'ALTER DATABASE ' . DB_NAME . ' CHARACTER SET utf8 COLLATE ' . $db_collate );
    	$statements[] = 'USE <code>' . DB_NAME . '</code>';
    
    	$tables = array();
    	$results = mysql_get_results( 'SHOW TABLE STATUS' );
    	foreach ( $results as $row ) {
    		$tables[] = $row['Name'];
    		if ( ! preg_match( '/utf8_/', $row['Collation'] ) ) {
    			$statements[] = 'ALTER TABLE <code>' . $row['Name'] . '</code> DEFAULT CHARACTER SET utf8 COLLATE ' . $db_collate;
    		}
    	}
    
    	$_types = array(
    		'VARCHAR'  => 'VARBINARY',
    		'LONGTEXT' => 'LONGBLOB',
    		'TINYTEXT' => 'TINYBLOB',
    		'CHAR'     => 'BINARY',
    		'TEXT'     => 'BLOB',
    	);
    
    	foreach ( $tables as $table ) {
    		$columns  = mysql_get_results( 'SHOW FULL COLUMNS FROM <code>' . $table . '</code>' );
    		$indexes  = mysql_get_results( 'SHOW INDEX FROM <code>' . $table . '</code>' );
    		$fulltext = array();
    		foreach ( $indexes as $index ) {
    			if ( $index['Index_type'] != 'FULLTEXT' ) {
    				continue;
    			}
    			if ( ! isset( $fulltext[ $index['Key_name'] ] ) ) {
    				$fulltext[ $index['Key_name'] ] = array();
    				$fulltext[ $index['Key_name'] ][ $index['Seq_in_index'] ] = $index['Column_name'];
    			}
    		}
    		$_fulltext = array();
    
    		foreach ( $columns as $column ) {
    			if ( ! preg_match( '/utf8_/', $column['Collation'] ) ) {
    				foreach ( $fulltext as $index_name => $index ) {
    					if ( in_array( $column['Field'], $index ) ) {
    						$statements[] = "ALTER TABLE <code>$table</code> DROP INDEX <code>$index_name</code>";
    						$_fulltext[]  = "ALTER TABLE <code>$table</code> ADD FULLTEXT <code>$index_name</code> (" . join(', ', array_map( create_function( '$s' , 'return "<code>$s</code>";' ), $index ) ) .")";
    						unset( $fulltext[ $index_name ] );
    					}
    				}
    			}
    		}
    
    		foreach ( $columns as $column ) {
    			if ( $column['Collation'] == '' ) {
    				continue;
    			}
    			if ( ! preg_match( '/utf8_/', $column['Collation'] ) ) {
    				$c    = '';
    				$type = strtoupper( $column['Type'] );
    				if ( preg_match( '/^(ENUM|SET)/', $type ) ) {
    					$null         = ( $column['Null'] == 'NO' ? 'NOT NULL' : 'NULL' );
    					$default      = ( $column['Default'] ? 'DEFAULT \'' . mysql_real_escape_string( $column['Default'] ) . '\'' : '' );
    					$statements[] = trim( "ALTER TABLE <code>$table</code> CHANGE $column[Field] $column[Field] $type CHARACTER SET utf8 $null $default" );
    				} else {
    					$btype = str_replace( array_keys( $_types ), $_types, $type );
    					if ( $type != $btype ) {
    						$statements[] = "ALTER TABLE <code>$table</code> CHANGE <code>$column[Field]</code> <code>$column[Field]</code> $btype";
    						$statements[] = "ALTER TABLE <code>$table</code> CHANGE <code>$column[Field]</code> <code>$column[Field]</code> $type CHARACTER SET utf8 COLLATE $db_collate";
    					} else {
    						fprintf( STDERR, "WARNING: No binary equivalent for $type. Data scrambling is likely to occur.\n" );
    						$statements[] = "ALTER TABLE <code>$table</code> CHANGE <code>$column[Field]</code> <code>$column[Field]</code> $type CHARACTER SET utf8 COLLATE $db_collate";
    					}
    				}
    			}
    		}
    
    		foreach ( $_fulltext as $index ) {
    			$statements[] = $index;
    		}
    	}
    	echo join( ";\n", $statements );
    	echo ";\n";
    }
    
    echo utf8ize_generator();
    

    And I didnt even get the string ‘hello world’

    Plugin Author Presslabs

    (@presslabs)

    This is because you have in same time activated the plugin Utf8ize and the function utf8ize_generator is already defined into the plugin. Use another name for the function in debug bar console or deactivate the plugin when you use the debug bar console.

    • This reply was modified 7 years, 4 months ago by Presslabs. Reason: add an alternative
    Thread Starter mll

    (@mll)

    Thanks you. So I disabled Utf8ize and then I saw that it doesn’t seem to go very far : it looks like mysql_connect( DB_HOST, DB_USER, DB_PASSWORD ) or die( 'Could not connect: ' . mysql_error() ); is the culprit :

    Plugin Author Presslabs

    (@presslabs)

    Can you check if the function exists?

    
    <?php
    if ( function_exists( 'mysql_connect' ) ) {
        print "mysql_connect function exists!\n";
    } else {
        print "The function mysql_connect does not exists!\n";
        if ( function_exists( 'mysqli_connect' ) ) {
            print "mysqli_connect function exists!\n";
        } else {
            print "The function mysqli_connect does not exists!\n";
        }
    }
    
    • This reply was modified 7 years, 4 months ago by Presslabs.
    Thread Starter mll

    (@mll)

    Output is : “The function mysql_connect does not exists! mysqli_connect function exists! “

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Blank screen instead of the SQL statements’ is closed to new replies.