【问题标题】:FPDF Error Cannot redeclare class FPDFFPDF 错误无法重新声明类 FPDF
【发布时间】:2017-04-17 07:08:18
【问题描述】:

我在使用 FPDF 时收到以下错误

Cannot redeclare class FPDF in /home/www/etrackbureau.co.za/fpdf.php on line 12

我没有在代码的任何其他部分声明其他类

<?php
//include_once('diag.php');
include_once('mysql_table.php');
include_once('../../fpdf.php');


class PDF extends PDF_MySQL_Table
{
function Header()
{
    //Title
    $this->SetFont('Arial','',18);
    $this->Cell(0,6,'World populations',0,1,'C');
    $this->Ln(10);
    //Ensure table header is output
    parent::Header();
}
}

//Connect to database
mysql_connect('localhost','stingin_assist','trevor74');
mysql_select_db('stingin_assist');

$pdf=new PDF();
$pdf->AddPage();
//First table: put all columns automatically
$pdf->Table('select * from bureau order by rep_date');
$pdf->AddPage();
//Second table: specify 3 columns
$pdf->AddCol('rank',20,'','C');
$pdf->AddCol('name',40,'Country');
$pdf->AddCol('pop',40,'Pop (2001)','R');
$prop=array('HeaderColor'=>array(255,150,100),
            'color1'=>array(210,245,255),
            'color2'=>array(255,255,210),
            'padding'=>2);
$pdf->Table('select name, format(pop,0) as pop, rank from country order by rank limit 0,10',$prop);

$pdf->Output();
?>

据我所知,我只宣布了一次课程。由于我是 FPDF 的新手,所以第二个问题是最好使用图形创建 PDF 文件并在其中写入。我搜索了论坛,并提到了很多。我正在寻找一个基线 PDF 系统来从我的数据库中的信息编写报告并将它们放入图表中

【问题讨论】:

    标签: php fpdf


    【解决方案1】:

    您正在组合 FPDF 网站上的几个脚本,但每个脚本的顶部都有以下代码:

    require('fpdf.php');
    

    例如,diag.php 中的代码将需要 sector.php,而该文件将需要 fpdf.phpmysql_table.php 中的代码也需要fpdf.php。这意味着fpdf.php 被包含多次,因此类 FPDF 被多次声明,这会导致您得到错误。将所有文件中的行更改为:

    require_once('fpdf.php');
    

    FPDF website 上的示例脚本很好地展示了可能的情况。要真正组合这些不同脚本的功能,您可能需要将这些脚本中的函数剪切并粘贴到一个大类中,或者更改谁 extends 什么,以获得多级(而不是多级)继承。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      • 1970-01-01
      • 2023-04-02
      • 2023-03-17
      • 1970-01-01
      • 2012-01-29
      • 2014-01-13
      相关资源
      最近更新 更多