PHP Script แปลง Convert MySQL Storage Type

By | 30/08/2018

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$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);
}

ใส่ความเห็น