FPDF 错误无法重新声明 class FPDF
FPDF Error Cannot redeclare class FPDF
我在使用 FPDF 时收到以下错误
Cannot redeclare class FPDF in /home/www/etrackbureau.co.za/fpdf.php on line 12
我不会在代码的任何其他部分声明其他 classes
<?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();
?>
据我所知,我只宣布 class 一次。由于我是 FPDF 的新手,第二个问题是最好创建带有图形的 PDF 文件并在其中写入。我搜索了论坛,提到了很多。我正在寻找一个基线 PDF 系统来根据我的数据库中的信息编写报告并将它们放入图表中
您正在组合来自 FPDF 网站的几个脚本,但每个脚本的文件顶部某处都有以下代码:
require('fpdf.php');
例如,diag.php
中的代码将需要 sector.php
,而该文件将需要 fpdf.php
。 mysql_table.php
中的代码也需要 fpdf.php
。这意味着 fpdf.php
被多次包含,因此 class FPDF 被多次声明,这会导致您收到错误。将所有文件中的行更改为:
require_once('fpdf.php');
FPDF website 上的示例脚本很好地展示了可能的情况。要实际组合这些不同脚本的功能,您可能需要将这些脚本中的功能剪切并粘贴到一个大 class 或更改 who extends
what,以获得多级(而非多重)继承。
我在使用 FPDF 时收到以下错误
Cannot redeclare class FPDF in /home/www/etrackbureau.co.za/fpdf.php on line 12
我不会在代码的任何其他部分声明其他 classes
<?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();
?>
据我所知,我只宣布 class 一次。由于我是 FPDF 的新手,第二个问题是最好创建带有图形的 PDF 文件并在其中写入。我搜索了论坛,提到了很多。我正在寻找一个基线 PDF 系统来根据我的数据库中的信息编写报告并将它们放入图表中
您正在组合来自 FPDF 网站的几个脚本,但每个脚本的文件顶部某处都有以下代码:
require('fpdf.php');
例如,diag.php
中的代码将需要 sector.php
,而该文件将需要 fpdf.php
。 mysql_table.php
中的代码也需要 fpdf.php
。这意味着 fpdf.php
被多次包含,因此 class FPDF 被多次声明,这会导致您收到错误。将所有文件中的行更改为:
require_once('fpdf.php');
FPDF website 上的示例脚本很好地展示了可能的情况。要实际组合这些不同脚本的功能,您可能需要将这些脚本中的功能剪切并粘贴到一个大 class 或更改 who extends
what,以获得多级(而非多重)继承。