Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Grund  >  CSV file db  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example PHP script
Class: CSV file db
Manipulation and navigation of CSV files
Author: By
Last change: Added a data manipulation section
Date: 10 years ago
Size: 1,205 bytes
 

Contents

Class file image Download
<?php

    
include("./file_db.class.php");
    
    
//Create new recordset
    
$rec = new file_db;
    
    
//Define the file to read
    
$rec->filename "./example.csv";
    
    
//Open File and load first recordset
    
$rec->open_db();
    
    
//Now first recordset can be displayed
    
echo $rec->record["name"]."-".$rec->record["city"]."<br>";
    
    
//If you want to display all use something like this
    
    
while (!$rec->EOF)
    {
        echo 
$rec->record["name"]."-".$rec->record["city"]."<br>";
        
$rec->move_next();
    }
    
    
//You can also start with the last recordset
    
    
$rec->move_last();
    while (!
$rec->BOF)
    {
        echo 
$rec->record["name"]."-".$rec->record["city"]."<br>";
        
$rec->move_prev();
    }
    
    
//Now lets manipulate...
    //First select the recordset
    
    
$rec->move_first();
    
$rec->move_next();
    
    
//Echo some contents
    
echo $rec->record["name"];
    
    
//Change some content
    
$rec->record["name"] = "Kai-Uwe";
    
    
//Update the selection
    
$rec->update();
    
    
    
//Now add a new recordset
    
$rec->add_new();
    
    
//Now add the content
    
$rec->record["name"]="Pierre";
    
$rec->record["city"]="Lyon";
    
$rec->record["country"]="France";
    
    
//At last you have to update the db
    
    
$rec->update();
    
    
$rec->move_first();
    
$rec->delete();
    
    
    
$rec->close_db();
?>