Ask for a PHP question. Make an upgrade program
I want to do an upgrade program for the website
I thought of a simple upgrade method. But do not know how to achieve. Special come to help
index.php is the upgrade file
There are still a lot of SQL files in the directory.
For example: 1.sql 2.sql 3.sql 4.sql 5.sql
So. For example, this version of the site is 2
Then when executing the index.php file in the browser: Automatically load or import 2.sql files. After the 2.sql import is successful. Automatic execution of SQL files larger than 2
Then the automatic down execution of 3.sql 4.sql 5.sql until after the completion of 5.sql is not bigger than the 5.sql system prompts for upgrade success
Don't know how to do this?
PS upgrade file is not necessarily 12345 20140101.sql 20140202.sql 20140303.sql
In short, judgment is bigger than itself. If there is bigger than itself, proceed without stopping.
I beg you to teach me how to achieve this.
Thank you
------to solve the idea----------------------
Is the version of the website written in the database?
$sqlfile = Array (
' 1 ' = ' 1.sql ',
' 2 ' = ' 2.sql ',
' 3 ' = ' 3.sql ',
' 4 ' = ' 4.sql ',
' 5 ' = ' 5.sql ',
);
while (1) {
Get Current version
$version = mysql_query ("Select version from version");
if ($version >=count ($sqlfile)) {
Break
}else{
$sql = $sqlfile [$version +1];
Read the SQL file and execute
echo ' Update '. ($version + 1). ' Success ';
}
}
echo ' Update complete ';
?>