Welcome to our website.

A PHP Converter for Moving PageCookery Data to Microfan

Here is a small conversion script for anyone who needs to migrate data from PageCookery to Microfan. Save the code below as convertpc2mf.php, place it in the root directory of your PageCookery installation, and run it from there.

The script reads the entry and reply tables from the PageCookery database, then generates SQL statements that can be copied into phpMyAdmin and executed against the Microfan database. Before copying the generated SQL, enter the custom table prefix used by your Microfan installation. If no prefix is provided, the script uses mf_ by default.

<html>
<head>
<title>PageCookery转微饭程序 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
    textarea {width:100%;height:200px;}
    form {width:400px;}
    button {float:right;}
    #footer {width:100%;text-align:center;position:fixed;bottom:0px;}
</style>
</head>
<body>
<?php
    error_reporting(E_ALL ^ E_NOTICE);
    require_once 'config.php';
    function sql_query($sqlcon){
      $con=mysql_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PSSWORD);
      mysql_select_DB(DATABASE_DB_NAME);
      mysql_query("SET NAMES 'utf8'");
      $result = mysql_query($sqlcon);
      mysql_close($con);
      return $result;
    }
    $entry_pc = sql_query('SELECT * FROM entry');
    $reply_pc = sql_query('SELECT * FROM reply');
    $prefix = $_GET['prefix'];
    if ($prefix == "") $prefix = "mf_";
?>
<form action="convertpc2mf.php" method="GET">
请输入你的微饭数据库的自定义前缀:<input name="prefix" type="text" value="mf_">(不要忘了最后还有一个'_'哦!)
<input type="submit" value="确认">
</form>
<p>复制下列代码并在phpMyadmin中执行即可<a href="https://p.upyun.lithub.cc/404.png?url=http%3A%2F%2Fimg1.dnschina.net%2Ffiles%2F68%2Finsert_into_sql.png" target="_blank" style="font-size:12px;">不懂请看图</a></p>
<textarea>
    <?php
      while ($entry = mysql_fetch_object($entry_pc)) {
        $content = $entry -> content;
        echo "INSERT INTO `" . $prefix . "entry` VALUES ";
        echo "('','" . $entry -> userid . "','','','','" . addslashes($content) . "','" . $entry -> time . "','" . $entry -> from . "','0','','','');";
        echo "\n";
      }
    while($reply =mysql_fetch_object($reply_pc)){
        $nickname = $reply -> nickname;
        $geo = $reply -> geo;
        if ($nickname == "" && $geo != "owner") {
            $nickname = $geo . '网友';
            $userid = 0;
        } elseif ($nickaname == "" && $geo == "owner" ) {
            $userid = 1;
            $nickname = "";
        }
        echo "INSERT INTO `" . $prefix . "entry` VALUES";
        echo "('','" . $userid . "','" . $nickname . "','" . $reply -> email . "','" . $reply -> url . "','" . $reply -> message . "','" . $reply -> time . "','网页','" . $reply -> entryid . "','','','');";
        echo "\n";
    }
  ?>
</textarea>
<p style="margin-top:15px;color:#AAA;">
        友情提示:<br>
        1.请确定你是在'微饭'的表中执行代码,并确保微饭已经安装,即存在entry和reply两个表。<br>
        2.请输入你的'微饭'表前缀并确定后再复制代码,否则可能导致失败。<br>
        3.部分对数据库架构进行过变动的用户可能会导入失败,请修改相关代码后再进行导入。<br>
        4.导入前请将原数据库进行备份,以免发生意外损失。
</p>
<div id="footer">Powered By <a href="https://imnerd.org">怡红公子</a> | 欢迎报告 <a href="mailto:[email protected]">BUG</a></div>
<body>
</html>

A few things are worth checking before running the generated SQL:

  1. Make sure the SQL is executed in the Microfan database, not the PageCookery database.
  2. Microfan should already be installed, and its required tables should exist before importing data.
  3. Enter the correct Microfan table prefix and confirm it before copying the generated SQL. The prefix should include the trailing underscore, such as mf_.
  4. If the database structure has been customized, the import may fail. In that case, adjust the relevant fields in the script before importing.
  5. Back up the original database before doing the migration, so the data can be restored if anything goes wrong.

Related Posts