Last active
September 9, 2016 12:22
-
-
Save foozlereducer/b8c52701d972d93ee57939b4735ef7e8 to your computer and use it in GitHub Desktop.
install.php mysql INNODB helper code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // found in: ci-build/wordpress-tests-lib/includes/install.php | |
| // reference: https://core.trac.wordpress.org/ticket/34692 | |
| /** | |
| * Shell function that returns the version of mysql regardless of using PDO or MySQLi | |
| * @return string - the numbered version of mysql i.e 5.7.14 | |
| */ | |
| function get_mysql_version() { | |
| $output = shell_exec('mysql -V'); | |
| preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); | |
| if ( is_array( $version ) ) { | |
| return $version[0]; | |
| } | |
| return; | |
| } | |
| // Use PDO if enabled otherwise fallback to mysqli check | |
| $mysql_version = get_mysql_version(); | |
| // Perform version comparing to decide what storage engine string should be used. | |
| if ( isset( $mysql_version ) ) { | |
| $mysql_version = explode( '.', $mysql_version ); | |
| if ( is_array( $mysql_version ) ) { | |
| // We know that mysql version 5.7+ use default_storage_engine so match the first two numbers | |
| // and ensure that it is equal to or greater than 5.7 | |
| if ( (int) $mysql_version[0] >= 5 && (int) $mysql_version[1] >= 7 ) { | |
| $wpdb->query( 'SET default_storage_engine = INNODB' ); | |
| } else { | |
| $wpdb->query( 'SET storage_engine = INNODB' ); | |
| } | |
| } else { | |
| // fallback when $mysql_version is not set as an array | |
| $wpdb->query( 'SET storage_engine = INNODB' ); | |
| } | |
| } else { | |
| // Load as fallback | |
| $wpdb->query( 'SET storage_engine = INNODB' ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment