【发布时间】:2016-07-13 02:09:32
【问题描述】:
所以我有一个关于 FPDF 库的问题,该库用于生成包含 MYSQL-DB 数据的 PDF 文档。
在 PHP 5 中,所有代码都在工作,我得到以下输出:
我用这个代码来生成它:
<?php
require('mysql_table.php');
class PDF extends PDF_MySQL_Table
{
function Header()
{
$this->SetFont('Arial','',18);
$this->Cell(0,6,'test',0,1,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}
//Connect to database
mysql_connect('localhost','root','');
mysql_select_db('testDB');
$pdf=new PDF();
$pdf->AddPage();
$prop=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>2);
$pdf->Table('SELECT `first_name`, `last_name`, `title` FROM a3324_userWHERE DELETED = 0 order by `date_entered`',$prop);
header('Content-type: test/pdf');
$pdf->Output('test'.".pdf", 'D');
?>
当我尝试在我的 Linux 服务器中实现相同的功能时,它指出我应该使用 mysqli_*,因为 PHP 7 不支持旧版本。
我已经用它们的 mysqli-variant 替换了所有函数,并得到了以下结果:
如您所见,它可以正常工作,只是它不从数据库中检索列名。我做了一些研究并注意到检索列名的旧函数如下:
foreach($this->aCols as $i=>$col)
{
if($col['c']=='')
{
if(is_string($col['f']))
$this->aCols[$i]['c']=ucfirst($col['f']);
else
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
}
}
由于需要使用mysqli,发现mysql_field_name()这个函数已经不用了,换成了mysqli_fetch_field()或者mysqli_fetch_fields()。
我尝试将mysql_field_name($res,$col['f']) 替换为mysqli_fetch_fields($res,$col['f']) 或mysqli_fetch_field(),但这也不起作用。
我的问题可能出在哪里?
【问题讨论】:
标签: php pdf mysqli fpdf generated