Posted By

mattkenefick on 05/20/08


Tagged

mysql file expand


Versions (?)

PHP Class: Expand MySQL File


 / Published in: PHP
 

Expands a MySQL / Gzipped file and executes it's queries.

  1. <?php
  2. /**************************************
  3.  seesaw associates | http://seesaw.net
  4.  
  5.  client:
  6.  file:
  7.  description:
  8.  
  9.  Copyright (C) 2008 Matt Kenefick(.com)
  10. **************************************/
  11.  
  12. ini_set("memory_limit","100M");
  13.  
  14. class expandSQL{
  15.  
  16. var $db;
  17.  
  18. function expandSQL($db){
  19. $this->db = $db;
  20. }
  21.  
  22. function expand($file){
  23. $sql = $this->readFile($file);
  24. foreach($sql as $query)
  25. $db->query($query);
  26.  
  27. return true;
  28. }
  29.  
  30. function readFile($filename){
  31. $fileExt = $this->getext($filename);
  32.  
  33. if(file_exists($filename)){
  34. $nLines = '';
  35.  
  36. switch( strtolower($fileExt) ){
  37. case 'gz':
  38. $lines = gzfile($filename);
  39. break;
  40. case 'sql':
  41. $lines = readfile($filename);
  42. break;
  43. }
  44.  
  45. foreach($lines as $line) {
  46. if(substr($line,1,1)!='-' && substr($line,1,1)!='')
  47. $nLines .= $line;
  48. }
  49.  
  50. return split(';',$nLines);
  51. }
  52. }
  53.  
  54. function getext($filename){
  55. $ext = split('\.',$filename);
  56. $ext = $ext[count($ext)-1];
  57. return $ext;
  58. }
  59. }
  60.  
  61. ?>

Report this snippet  

You need to login to post a comment.