2016-07-13 12 views
1

그래서 MYSQL-DB의 데이터로 PDF 문서를 생성하는 데 사용되는 FPDF 라이브러리와 관련하여 문제가 있습니다.FPDF/PHP : 열 이름이 Mysqli_fetch_fields()로 검색되지 않습니다.

PHP 5에서

, 모든 코드가 작동하고, 나는 다음과 같은 출력을 얻을 :

enter image description here

내가 그것을 생성이 코드를 사용했습니다 :

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

?> 

나는 나의 리눅스 서버에서 같은 것을 성취하려고 시도했다. 이전 버전이 PHP 7에서 지원되지 않기 때문에 mysqli_ *를 사용해야한다고 언급했다.

나는 그들의 mysqli - 변형에 의해 모든 기능을 대체하고 다음과 같은 결과에 온 : enter image description here

당신이 볼 수 있듯이,이 데이터베이스에서 열 이름을 검색하지 않는 것을 제외하고는 작동합니다. 나는 몇 가지 조사를 수행하고 열 이름을 검색하기 위해 기존의 기능은 다음과 같은 것을주의했다 : 내가 mysqli를 사용하는 데 필요한 된 이후

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'])); 
     } 
    } 

, 나는 기능 mysql_field_name() 더 이상 사용되지 않음을 발견하고 mysqli_fetch_field()로 대체되었다 또는 mysqli_fetch_fields().

mysql_field_name($res,$col['f'])mysqli_fetch_fields($res,$col['f']) 또는 mysqli_fetch_field()으로 바꾸려고했지만이 방법도 작동하지 않았습니다.

내 문제는 어디에 위치해 있습니까?

답변

1

시도 :

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(mysqli_fetch_field_direct($res, $col['f'])->name); 
    } 
} 

또는 사용 :

function mysqli_field_name($res, $fieldnr) { 
    $finfo = mysqli_fetch_field_direct($res, $fieldnr); 
    return is_object($finfo) ? $finfo->name : false; 
} 
+0

감사합니다! 나는 mysqli_fetch_field_direct() 함수에 대해 알지 못했다! 내 코드가 훌륭하게 작동하고 있습니다! –