2011-07-16 86 views
1

我目前正在嘗試編寫一個腳本來將數據庫從專有CMS系統遷移到Joomla 1.6數據庫。
我的代碼在最後一個「死亡」處拋出一個錯誤。 (對不起,我自學了沿途PHP,我知道我沒有使用正確的術語做的一切。)將專有CMS數據庫遷移到Joomla數據庫

<?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'

任何想法?謝謝!

回答

1

fulltext是MySQL保留關鍵字。如果你想用它作爲列名,你需要使用反標,如下:

`fulltext` 
+0

你是我的英雄。記住addslashes和mysql_real_escape_string在需要的地方後,它可以很好地工作。 – Dennis

+0

我試圖給你投票,但這是我第一次發帖,對不起。 – Dennis

1

「fulltext」是一個MySQL reserved word,因此要麼將其加入反引號(例如`fulltext`),要麼爲該字段使用不同的名稱。