将专有CMS数据库迁移到Joomla数据库

时间:2011-07-16 08:11:27

标签: php mysql joomla content-management-system migration

我正在尝试编写一个脚本,将数据库从专有的CMS系统迁移到Joomla 1.6数据库。
我的代码在最后一次“死”时抛出一个错误。 (对不起,我一直在自学PHP,我知道我没有使用适当的术语。)

<?php
$username="root";
$password="";
$database="DATABASE";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM post3";
$result=mysql_query($query);

$num=mysql_num_rows($result);

mysql_close();

$i=0;
while ($i < $num) {

$postid=mysql_result($result,$i,"postid");
echo "$postid <br/>";

$poster=mysql_result($result,$i,"poster");
echo "$poster <br/>";

$department=mysql_result($result,$i,"department");

if($department=="LIFE"){
$department="12";}
elseif ($department=="NEWS"){
    $department="11";}
    elseif ($department=="SPORTS"){
        $department="13";}
        echo "$department <br/>";

$milestone=mysql_result($result,$i,"milestone");
echo "$milestone <br/>";

$date= date('Y-m-d H:i:s', $milestone);
echo "$date <br/>";

$title=mysql_result($result,$i,"title");
echo "$title <br/>";

$preview=mysql_result($result,$i,"preview");
if (empty($preview)) {
   $preview=$title;
}
echo "$preview<br/>";

$alias=str_replace(" ","-", $title);
echo "$alias <br/>";

$bodytext=mysql_result($result,$i,"body_text");
echo "$bodytext <br/>";

$edited=mysql_result($result,$i,"edited");
echo "$edited <br/>";

$pop=mysql_result($result,$i,"pop");
echo "$pop <br/>";

echo "$i Records Copied<br/>";


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DATABASE", $con);

$sql="INSERT INTO conversion (id, title, alias, introtext, fulltext, state, sectionid, mask, catid, created, created_by, modified, modified_by, checked_out, checked_out_time, publish_up, publish_down, version, parentid, ordering, access, hits, featured, language)
VALUES
('$postid','$title','$alias','$preview','$bodytext','1','0','0','$department','$date','$poster','$date','$poster','0','0000-00-00 00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','$edited','0','$i','1','$pop','0','*')";

if (!mysql_query($sql,$con))
  {
  die ("Query failed: " . mysql_error() . " Actual query: " . $sql);

  }
echo "Success <br/>";

mysql_close($con);

$i++;
}

?>

它可以解决所有问题,但会抛出此错误: 查询失败:您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在第1行的'fulltext,state,sectionid,mask,catid,created,created_by,modified,modified'附近使用正确的语法

有什么想法吗?谢谢!

2 个答案:

答案 0 :(得分:1)

“fulltext”是一个MySQL reserved word,因此要么将其括在反引号中(例如`fulltext`),要么为该字段使用不同的名称。

答案 1 :(得分:1)

fulltext是MySQL保留的关键字。如果要将其用作列名,则需要使用反引号,如:

`fulltext`