Convert all tables from MyISAM to InnoDB using PHP

2Fast2BCn

New member
Joined
May 27, 2016
Messages
10
Points
0
Normally when you create one table in MySQL Storage Engine, you will have many styles to choose from. Including 3 types of storage that most use are InnoDB, MyISAM and Memory.

If for any reasons you need to change the type from MyISAM to InnoDB or vice versa. PHP will help you do that.

Code:
<?php
// connect your database here first
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'root';
 
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    $dbname = 'databasename';
    mysql_select_db($dbname);
 
// Actual code starts here
    $sql = "SHOW tables";
    $rs = mysql_query($sql);
    while($row = mysql_fetch_array($rs))
    {
        $tbl = $row[0];
        $sql = "ALTER TABLE $tbl ENGINE=INNODB";
        mysql_query($sql);
    }
?>
Now your task is change the parameters such as $dbhost, $dbuser, $dbpass, $dbname to match the information on your hosting.

Hope to hear other ways from all of you here.
 

Web Marketing Tool

New member
Joined
Apr 30, 2016
Messages
41
Points
0
One note, this code won't work in php 7. mysql_* functions are no longer supported. mysqli is the closest alternative as far as being able to easily convert this code to using a supported method.
 
Latest threads
Replies
4
Views
652
Replies
0
Views
94
Replies
1
Views
133
Replies
1
Views
130
Recommended threads
Replies
2
Views
1,330
Replies
1
Views
2,287
Replies
7
Views
3,749
Replies
0
Views
5,199

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top