PHP Script แปลง Convert MySQL Storage Type

By | 30/08/2018

วิธีใช้คือ เอา code วางในไฟล์ แล้วสั่ง php -f ตามด้วยชื่อไฟล์

[cc lang=”php”]
$servername = “localhost”;
$username = “da_admin”;
$password = “pass”;

$dbc = $argv[1];
#$dbc = ‘db’;

// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
die(“Connection failed: ” . mysqli_connect_error());
}
echo “Connected successfully”;

$sql = “SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = ‘”.$dbc.”‘
AND ENGINE = ‘InnoDB'”;

$rs = mysqli_query($conn,$sql);

mysqli_select_db($conn,$dbc);

while($row = mysqli_fetch_array($rs))
{
$tbl = $row[0];
#echo $tbl;
$sql = “ALTER TABLE `$tbl` ENGINE=MyISAM”;
mysqli_query($conn,$sql);
}
[/cc]

ใส่ความเห็น