Apply for Zend Framework Certification Training

Corephp





step 1

<?php
Class dbObj{
/* Database connection start */
var $dbhost = "localhost";
var $username = "root";
var $password = "";
var $dbname = "classicmodels";
var $conn;
function getConnstring() {
$con = mysqli_connect($this->dbhost, $this->username, $this->password, $this->dbname) 
or die("Connection failed: " . mysqli_connect_error());

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$this->conn = $con;
}
return $this->conn;
}
}

Step 2

<?php
//include connection file 
include_once("connection.php");
include_once("fpdf/fpdf.php");

class PDF extends FPDF
{
// Page header
function Header()
{
    // Logo
    $this->Image("flower.jpg",10,-1,70);
    $this->SetFont('Arial','B',13);
    // Move to the right
    $this->Cell(60);
    // Title
    $this->Cell(60,10,'Employee List',1,0,'C');
    // Line break
    $this->Ln(20);
}

// Page footer
function Footer()
{
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

$db = new dbObj();
$connString =  $db->getConnstring();
$display_heading = array('employeeNumber'=>'employeeNumber', 'lastName'=>
 'lastName', 'firstName'=> 'firstName','email'=> 'email',);

$result = mysqli_query($connString, "SELECT employeeNumber, lastName, firstName,
 email FROM employees") or die("database error:". mysqli_error($connString));
//$header = mysqli_query($connString, "SHOW columns FROM employees");

$pdf = new PDF();
//header
$pdf->AddPage();
//foter page
$pdf->AliasNbPages();
$pdf->SetFont('Arial','B',12);
//foreach($header as $heading) {
//$pdf->Cell(40,12,$display_heading[$heading['Field']],1);
//}
foreach($result as $row) {
    $pdf->Ln();
    foreach($row as $row=>$column)
        if($row =='email'){
            $pdf->Cell(75,12,$column,1);
        }else{
            $pdf->Cell(40,12,$column,1);
        }
}
    $pdf->Output();
?>                                    

< change date format How to show custom url using htaccess in php >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top