Documente Academic
Documente Profesional
Documente Cultură
For working with SQLite , XML and PHP you need to install the SQLite2 and or SQLite-3 and PHP-5
or above and enable DOM/XML extension in PHP.
Fortunately all the above get installed by default once you install database,webserver and PHP from a
typical linux CD (Fedora Core-5 or above, suse 10.1 , mandriva 2008 or any other )
For older linux you have to install sqlite-2 ,php-sqlite and DOM/XML separately.
Sqlite-2 is available from http://www.sqlite.org
With the help of DOM/XML , PHP can decode any length of XML file and then can store easily in
SQLITE database.
In the first part we will read an xml file through a simple htnl uploader and PHP DOM/XML reader.
…................ upload.htm …...........
<html> <body>
<form enctype="multipart/form-data"
action="import.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<table width="600">
<tr> <td>Names file:</td>
<td><input type="file" name="file" /></td>
<td><input type="submit" value="Upload" /></td> </tr>
</table> </form>
</body> </html>
if ( $_FILES['file']['tmp_name'] ) {
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$xname = $_FILES['file']['name'];
echo '<br>File Name:'.$xname; // Print file name here.
$rows = $dom->getElementsByTagName( 'Row' );
$first_row = true; // Or you can make it false if it contains headers.
Once downloaded , put them in the document root directory of your webserver. Supply any xml file and
then see how PHP outputs the first five columns on the browser screen. For testing just take out any
excel file having only one worksheet. Open it in openoffice or in MicroSoft excel an save it as xml file
and the sample xml file is ready.
S Bera
Mumbi