开发者

Migrating a proprietary CMS database to a Joomla database

I'm currently trying to write a script to migrate the database from a proprietary CMS system to a Joomla 1.6 database.

My code is throwing an error at the last "die". (Sorry, I've taught myself PHP along the way, I know I don't use the proper terminology for everything.)

<?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))
  {
  开发者_如何学Cdie ("Query failed: " . mysql_error() . " Actual query: " . $sql);

  }
echo "Success <br/>";

mysql_close($con);

$i++;
}

?>

It echos everything out fine, but throws this error: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fulltext, state, sectionid, mask, catid, created, created_by, modified, modified' at line 1

Any ideas? Thank you!


fulltext is a MySQL reserved keyword. If you want to use it as a column name, you need to use backtickts, as in:

`fulltext`


"fulltext" is a MySQL reserved word, so either enclose it in backticks (e.g. `fulltext`) or use a different name for the field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜