【问题标题】:Migrating a proprietary CMS database to a Joomla database将专有 CMS 数据库迁移到 Joomla 数据库
【发布时间】:2011-07-16 08:11:26
【问题描述】:

我目前正在尝试编写一个脚本来将数据库从专有 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' 附近使用正确的语法

有什么想法吗?谢谢!

【问题讨论】:

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


    【解决方案1】:

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

    `fulltext`
    

    【讨论】:

    • 你是我的英雄。记住在必要的地方添加斜杠和 mysql_real_escape_string 后,它可以完美运行。
    • 我试图给你投票,但这是我第一次发帖,抱歉。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2019-02-10
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2011-09-27
      • 2016-12-05
      • 1970-01-01
      • 2018-06-22
      • 2011-07-29
      相关资源
      最近更新 更多