MySQL Modify table engine: PHP bulk conversion MySQL table engine

Source: Internet
Author: User
Tags array modify sql mysql

Some times you may need to bulk convert the MySQL table engine, as follows for PHP operations
<?php
/**
* Bulk conversion MySQL table engine
*/
Error_reporting (E_all);
Database Connection Configuration
$host = ' localhost ';
$username = ' root ';
$passwd = ';
$database = ' Test ';
To convert the library name configuration, the multi-Library transformation adds configuration elements
$configs = Array ($database);
Transformation Configuration
$convert _rule = Array (
' From ' => ' InnoDB ',
' To ' => ' MyISAM '
);
Mysql_engine_convert ();
/**
* Conversion function
*/
function Mysql_engine_convert ()
{
Global $host, $username, $passwd, $configs, $convert _rule;
if (($conn = mysql_connect ($host, $username, $passwd))!== false)
{
foreach ($configs as $db _name)
{
mysql_select_db ($db _name) or exit (' not found DB: '. $db _name);
$tables = mysql_query ("Show full Tables");
while ($table = Mysql_fetch_row ($tables))
{
if ($table [1] = = ' view ') continue;
$sql = "Show Table status from {$db _name} where name= ' {$table [0]} '";
if ($result = mysql_query ($sql))
{
$table _status = mysql_fetch_row ($result);
if (Strtolower ($table _status[1]) = = Strtolower ($convert _rule[' from '))
mysql_query ("ALTER TABLE {$table [0]} engine = {$convert _rule[' to '}");
}
}
echo $db _name, ': All Tables engine are ', $convert _rule[' to '], "\ n";
}
} else {
echo "DB error\n";
}
This article links http://www.cxybl.com/html/wlbc/Php/20120607/28510.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.