Thursday, January 5, 2017

mysqli database engine change to MyISAM using php

<?php
$conn = mysqli_connect('localhost','root','');
$dbs = array();
$dbs[] = $_GET['database'];

foreach($dbs as $v){
    mysqli_select_db($conn, $v);
    $q = mysqli_query($conn, 'show tables');
    $tables = array();
    while($r = mysqli_fetch_row($q)){
        $tables[] = $r[0];
    }
$c=0;
    foreach($tables as $t){
        echo "do $v.$t<br>";
        mysqli_query($conn, 'ALTER TABLE `'.$t.'` ENGINE=MyISAM;');
$c++;
    }
echo $c." tables changed.";
}
mysqli_close($conn);

No comments: