Wednesday, July 4, 2007

PHP to PDF with Oracle Database

I never think that PHP can do this. It's still about my database labwork. Yesterday, I've got a problem with creating a report from PHP. And then I asked my friend, Wima because I had to finish web engine for my application. We have the same project so we divided it into two parts. He made the report and I handled the PHP web engine.

First, a trying to create an excel document from PHP failed. We couldn't debug where is the error although didn't sleep for a long long night. In the next day, Wima tried to open sample application in XAMMP at localhost. We used XAMMP bundle where Apace, PHP, and MySQL integrated here. Wanna know the code? We still used Oracle as database. Here's the code:

//connection to Oracle
include ('koneksi.php');

$query = "select no_kamar_inv , kamar_jenis_inv,kamar_kategori,
kamar_harga from kel65_inventaris_kamar order by no_kamar_inv";
$stmt = ociparse($c,$query);

//php class to create pdf
include ('class.ezpdf.php');
$pdf = new Cezpdf();

$pdf->ezText('Laporan Data Kamar',14);
$pdf->ezText('Sistem Informasi E-Inap',10);

while ($row=oci_fetch_array($stmt))
$data[$i]=array('NO KAMAR'=>$row[0],'JENIS KAMAR'=>$row[1],
'KATEGORI KAMAR'=>$row[2], 'HARGA KAMAR'=>$row[2]);



How to connect to Oracle is described in article PHP Connection to Oracle.
You will find some different things here if you use another version of XAMMP. But don't worry, it's just a little bit different. Have a nice try with PHP PDF report...

Special thanks for Wima

No comments: