Advertisement
Guest User

Untitled

a guest
Jul 28th, 2010
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. relevant controller methods:
  2.  
  3.  
  4.  
  5.     function console()
  6.     {
  7.        
  8.         $data['myError'] = $this->read_openx_data($_SERVER['DOCUMENT_ROOT'] . "/junk/", "file.txt", "database_table_name", "\t", "\n", "1");
  9.        
  10.         $data['myVar'] = "Hello World<br />";
  11.        
  12.         $this->load->view('console', $data);
  13.     }
  14.  
  15.     function read_openx_data($local_path, $filename, $tbl, $delimiter="\t", $terminated="\n", $ignore="1")
  16.     {
  17.        
  18.         // Load Model and assign custom object name
  19.         // Access like: $this->pdp->function()
  20.         $this->load->model('performance_data_push', 'pdp');
  21.        
  22.         // Perform the insert
  23.         if($this->pdp->insert_openx_data($local_path, $filename, $tbl, $delimiter, $terminated, $ignore))
  24.         {
  25.             return TRUE;
  26.         }
  27.         else
  28.         {
  29.            
  30.             // Send out an E-Mail
  31.             // ** See MY_email_helper.php to change recipient
  32.             $this->load->helper('email');
  33.            
  34.             $error   = $this->db->_error_message();
  35.             $subject = "Error Inserting OpenX Data";
  36.             $message = "There was an error inersting the OpenX Data into \"{$tbl}\"."
  37.                 . "\n\n\n"
  38.                 . "Data Dump\n\n"
  39.                 . "Local Path: {$local_path}\n"
  40.                 . "Filename: {$filename}\n"
  41.                 . "Table name: {$tbl}\n"
  42.                 . "Delimiter: {$delimiter}\n"
  43.                 . "Terminated At: {$terminated}"
  44.                 . "Lines Ignored: {$ignore}";
  45.                
  46.             send_error_email($subject, $message);
  47.            
  48.             show_error("Error inserting {$filename} into {$tbl} from {$local_path}. With error: {$error}");
  49.            
  50.         }
  51.        
  52.     }
  53.  
  54.  
  55.  
  56.  
  57.  
  58. relevant model methods
  59.  
  60.     function insert_openx_data($local_path, $filename, $tbl, $delimiter="\t", $terminated="\n", $ignore="1")
  61.     {
  62.        
  63.         // Define some variables
  64.         $file = $local_path . $filename;
  65.         $table = $tbl;
  66.        
  67.         // Structure the query for LOAD DATA INFILE
  68.         // Ignores the first line: IGNORE 1 LINES
  69.         $this->db->query('LOAD DATA INFILE "'.$file.'" INTO TABLE '.$table.' FIELDS TERMINATED BY "'.$delimiter.'" OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "'.$terminated.'" IGNORE '.$ignore.' LINES');
  70.  
  71.     }
  72.  
  73.  
  74.  
  75.  
  76. my view
  77.  
  78. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
  79. <html>
  80. <head>
  81. <meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
  82. <title>OpenX Data Aggregation Tool - Console</title>
  83. </head>
  84. <body>
  85.  
  86. <?php echo $myVar; ?>
  87. <?php echo $myError; ?>
  88.  
  89. </body>
  90. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement