1

这是一个将 joomfish(joomla 翻译组件)从 joomla 1.5 升级到 2.5 的脚本:

$db = new PDO("mysql:host=localhost;dbname=db;charset=UTF8", "root", "pass");

 $stmt = $db->prepare("select distinct(jfc.reference_id),c.catid,jfc.language_id,c.modified,c.modified_by,c.version,c.modified_by ,c.ordering,c.created_by,c.metadesc ,c.created_by_alias  from  jos_jf_content  jfc ,jos_content c where  jfc.reference_id = c.id and jfc.reference_table = 'content' ");
 $stmt->execute();

 $results = $stmt->fetchAll(PDO::FETCH_ASSOC);

    foreach($results as $row) {

        $count_row = $db->prepare("select * from jos_jf_content where reference_id = ? and language_id = ?");
        $count_row->bindValue(1, $row['reference_id']);
        $count_row->bindValue(2, $row['language_id']);

        $lang_code = $db->prepare("select lang_code from j25_languages where lang_id = ?");
        $lang_code->bindValue(1, $row['language_id']);
        $lang_code->execute();
        $l_code = $lang_code->fetch(PDO::FETCH_OBJ);
        $language_code = $l_code->lang_code;

        $count_row->execute();

            $title ="";
            $fulltext ="";
            $introtext ="";
            $alias ="";
            $published ="";

        while($col = $count_row->fetch(PDO :: FETCH_ASSOC))
        {
            if($col['reference_field'] == "title")
                    {
                        $title =  $col['value'];
                    }
                    if($col['reference_field'] == "fulltext")
                    {
                        $fulltext =  $col['value'];
                    }
                    if($col['reference_field'] == "introtext")
                    {
                        $introtext =  $col['value'];
                    }
                    if($col['reference_field'] == "alias")
                    {
                        $alias =  $col['value'];
                    }
                    $published = $col['published'];

        }

  $exe = $db->prepare("insert into j25_content (`title`,`alias`,`introtext`,`fulltext`,`published`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`version`,`ordering`,`metadesc`,`language`) values(:title,:alias,:introtext,:fulltext,:published,:categoryid,:created,:created_by,:created_by_alias,:modified,:modified_by,:version,:ordering,:metadesc,:language_code)");

  $exe->execute(array(':title' => $title,':alias' => $alias,':introtext' => addslashes($introtext),':fulltext' => addslashes($fulltext),':published' => ".$published.",':categoryid' => $row['catid'],':created' => date("Y-m-d H:i:s"),':created_by' => $row['created_by'],':created_by_alias' => "".$row['created_by_alias']."",':modified' => date("Y-m-d H:i:s"),':modified_by' =>$row['modified_by'],':version' => $row['version'],':ordering' => $row['ordering'],':metadesc' => $row['metadesc'],':language_code' => $language_code));

  $i = $db->lastInsertId('id');

  $asst =  $db->prepare("select asset_id from j25_categories where id = ? ");
  $asst->bindValue(1, $row['catid']);
  $asst->execute();
  $asst_id = $asst->fetch(PDO::FETCH_OBJ);
  $cassetid = $asst_id->asset_id;

  $sel =  $db->prepare("select lft,rgt FROM `j25_assets` where id = (SELECT max(id) FROM `j25_assets`)");
  $sel->execute();
  $select = $sel->fetch(PDO::FETCH_OBJ);
  $left = $select->lft;
  $right = $select->rgt;
  $left=$left+1;
  $right = $right+1;

    $stmt = $db->prepare("insert into  j25_assets (`parent_id`,`lft`,`rgt`,`level`,`name`,`title`) values(:cassetid,:left,:right,:level,:name,:title)");
    $stmt->execute(array(':cassetid' => $cassetid,':left' => $left,':right' => $right,':level' => 4,':name' => "com_content.article.".$i,':title' => $title));

    $insertedId = $db->lastInsertId('id');

    $update = $db->prepare("update j25_content set asset_id = ? where id = ?");
    $update->bindValue(1, $insertedId);
    $update->bindValue(2, $i);
    $update->execute();

    $stmt = $db->prepare("insert into j25_jf_translationmap (language,reference_id,translation_id,reference_table) values (:language_code,:reference_id,:translation_id,:content)");
    $stmt->execute(array(':language_code' => $language_code,':reference_id' => $row['reference_id'],':translation_id' => $i,':content' => 'content'));
}

代码行:

$language_code = $l_code->lang_code;

回报:

试图获取非对象的属性

我不是该脚本的作者,也不擅长 PHP,但我尝试过,print_r($l_code->lang_code);并且en-GB[lang_code] => en-GB. 我需要在此代码中更改什么?谢谢。

4

1 回答 1

1

该行$language_code = $l_code->lang_code > 0;设置$language_code为布尔值。尝试var_dump($l_code);var_dump($language_code);调试您的结果。您还应该检查是否$l_code实际上是一个对象,或者是否返回了 null。希望有帮助。

于 2016-08-18T12:23:34.320 回答