PHP Classes

File: agency.php

Recommend this page to a friend!
  Packages of Corey W.   MySQL Database & Model Classes   agency.php   Download  
File: agency.php
Role: Class source
Content type: text/plain
Description: Example Model Class
Class: MySQL Database & Model Classes
Manipulate MySQL database table records as objects
Author: By
Last change:
Date: 17 years ago
Size: 695 bytes
 

 

Contents

Class file image Download
<?php

require_once('../libraries/Model.php');

/**
 * Agency table model
 */
 
class Agency_Model extends Model {

    /**
     * Import CSV file into database
     *
     * @param   array   Data from CSV file
     */
    function import($data) {
    
        if (!is_array($data))
            return false;
        
        for ($i=0; $i<count($data); $i++) {
            for ($x=0; $x<count($data[$i]); $x++)
                $data[$i][$x] = trim($this->escape($data[$i][$x]));
            $new_data[] = '('.implode(',', $data[$i]).')';
        }
        
        $new_data = implode(',', $new_data);
        
        unset($this->fields[0]);
        $fields = implode(',', $this->fields);
        
        return $this->query("INSERT INTO agency ($fields) VALUES $new_data");
    
    }

}