HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]

Source for file upload_csv.php

Documentation is available at upload_csv.php

  1. <?php
  2. /**
  3.  * CSV upload script.
  4.  * A script which is used to upload a CSV into a specific table.
  5.  * @package HRDIODB
  6.  */
  7.  
  8. /**
  9.  * This file is part of HRDIODB.
  10.  *
  11.  * HRDIODB is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * HRDIODB is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with HRDIODB; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24.  */
  25.  
  26. /** Configuration file */
  27. require_once("conf.php");
  28. /** Debugging functions */
  29. require_once("debugging.php");
  30. /** HRDI database class */
  31. require_once("hrdi_db_class.php");
  32. /** CSV loader class */
  33. require_once("csv_loader_class.php");
  34.  
  35. // Check to make sure we have a file to upload
  36. if(!is_file(@$argv[1])){
  37.   error("You must specify a valid CSV file's name")
  38.   return FALSE;  
  39. }
  40.  
  41. /* The initial import of hrdi data uses much memory because we have 
  42.  * chosen to parse all data before uploading to the database
  43.  */
  44. ini_set('memory_limit'"64M")
  45.  
  46. // Set time limit to 0 so that the script never times out
  47.  
  48. /* Create an object for using pear to write to the database specified by the
  49.  * $dsn in the conf.php file. */
  50. $db new hrdi_db($dsn);
  51.  
  52. // Create the parser
  53. $parser new csv_loader();
  54.  
  55. // Pass the target database object to the parser
  56. $parser->set_db($db);
  57.  
  58. // Pass a list of table / key pairs to the parser from conf.php. 
  59. $parser->set_table_keys($table_keys);
  60.              
  61. // Pass the data file to the parser
  62. $parser->set_file($argv[1]);
  63.  
  64. // Parse the data file
  65. $parser->parse_file();
  66.  
  67. // Display a summary of the parsed data
  68. $parser->print_file_info();
  69.  
  70. // Push the parsed data to the database
  71. $parser->push_to_db();
  72. ?>

Documentation generated on Tue, 23 Jan 2007 22:57:53 -0500 by phpDocumentor 1.3.0RC6