PHP is a popular programming language now supports reading and writing DBF files (dBase). PHP has a set of special functions related to the handling of dBase. In order to use these functions, the PHP libraries like php_dbase.dll (in Windows) should be activated. But in this tutorial we will not use dBase related functions, but we will use one library (class) that I can from a collection site php class. Library is named phpxbase and built by Erwin Kooi.
Creating And Writing Files DBF
In this tutorial we'll create a simple DBF file called "mahasiswa.dbf" where in it contains the student data and its value. Field data will be stored is the NIM, the name and value. Student data will be loaded through a simple form.
File Name: tulis_dbf.php
In this tutorial we'll create a simple DBF file called "mahasiswa.dbf" where in it contains the student data and its value. Field data will be stored is the NIM, the name and value. Student data will be loaded through a simple form.
File Name: tulis_dbf.php
<html>
<head> <title> Student Value Added (Demo Write DBF file) </ title> </ head>
<body>
<h1> Added Value Students </ h1>
<form action="" method="post">
NIM: <input type="text" name="nim" maxlength="10"/> <br/>
NAME: <input type="text" name="nama" size="30"/> <br/>
VALUE: <input type="text" name="nilai" size="5"/> <br/>
<input type="submit" name="Simpan" value="Simpan"/>
<input type="reset" name="Reset" value="Reset"/>
</ form>
<? php
if (isset ($ _POST ['Save'])) {
/ / load data
$ NIM = $ _POST ['NIM'];
$ name = $ _POST ['name'];
$ value = $ _POST ['value'];
/ * load the required classes * /
require_once "phpxbase / Column.class.php";
require_once "phpxbase / Record.class.php";
require_once "phpxbase / Table.class.php";
require_once "phpxbase / WritableTable.class.php";
<head> <title> Student Value Added (Demo Write DBF file) </ title> </ head>
<body>
<h1> Added Value Students </ h1>
<form action="" method="post">
NIM: <input type="text" name="nim" maxlength="10"/> <br/>
NAME: <input type="text" name="nama" size="30"/> <br/>
VALUE: <input type="text" name="nilai" size="5"/> <br/>
<input type="submit" name="Simpan" value="Simpan"/>
<input type="reset" name="Reset" value="Reset"/>
</ form>
<? php
if (isset ($ _POST ['Save'])) {
/ / load data
$ NIM = $ _POST ['NIM'];
$ name = $ _POST ['name'];
$ value = $ _POST ['value'];
/ * load the required classes * /
require_once "phpxbase / Column.class.php";
require_once "phpxbase / Record.class.php";
require_once "phpxbase / Table.class.php";
require_once "phpxbase / WritableTable.class.php";
/ * define field * /
$ fields = array (
array ("NIM", DBFFIELD_TYPE_CHAR, 11),
array ("name", DBFFIELD_TYPE_CHAR, 50),
array ("value", DBFFIELD_TYPE_NUMERIC, 3, 0)
);
/ * create a new table * /
$ tableNew = XBaseWritableTable:: create ("mahasiswa.dbf", $ fields, false);
/ * insert data * /
$ r = & $ tableNew-> appendRecord ();
$ r-> setObjectByName ("NIM", $ NIM);
$ r-> setObjectByName ("name", $ name);
$ r-> setObjectByName ("value", $ value);
$ tableNew-> writeRecord ();
echo '<h2> Data successfully saved </ h2>';
$ fields = array (
array ("NIM", DBFFIELD_TYPE_CHAR, 11),
array ("name", DBFFIELD_TYPE_CHAR, 50),
array ("value", DBFFIELD_TYPE_NUMERIC, 3, 0)
);
/ * create a new table * /
$ tableNew = XBaseWritableTable:: create ("mahasiswa.dbf", $ fields, false);
/ * insert data * /
$ r = & $ tableNew-> appendRecord ();
$ r-> setObjectByName ("NIM", $ NIM);
$ r-> setObjectByName ("name", $ name);
$ r-> setObjectByName ("value", $ value);
$ tableNew-> writeRecord ();
echo '<h2> Data successfully saved </ h2>';
echo '<p> Click<a href="baca_dbf.php"> here </ a> to display the data </ p>';
/ * close the table * /
$ tableNew-> close ();
} / / end of if
?>
</ body>
</ html>
/ * close the table * /
$ tableNew-> close ();
} / / end of if
?>
</ body>
</ html>
0 comments on Creating And Writing Files DBF In PHP :
Post a Comment and Don't Spam!
Dont Spam please