| [ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2004 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 class dbExport 24 { 25 private $con; 26 private $prefix; 27 28 private $line_replacement = array( 29 "\n" => '\n', 30 "\r" => '\r', 31 '"' => '\"' 32 ); 33 34 public $fp; 35 36 function __construct(&$con,$out='php://output',$prefix=null) 37 { 38 $this->con =& $con; 39 $this->prefix = $prefix; 40 41 if (($this->fp = fopen($out,'w')) === false) { 42 return false; 43 } 44 } 45 46 function __destruct() 47 { 48 if (is_resource($this->fp)) { 49 fclose($this->fp); 50 } 51 } 52 53 function export($name,$sql) 54 { 55 $rs = $this->con->select($sql); 56 57 if (!$rs->isEmpty()) 58 { 59 fwrite($this->fp,"\n[".$name.' '.implode(',',$rs->columns())."]\n"); 60 while ($rs->fetch()) { 61 fwrite($this->fp,$this->getLine($rs)); 62 fflush($this->fp); 63 } 64 } 65 } 66 67 function exportAll() 68 { 69 $tables = $this->getTables(); 70 71 foreach ($tables as $table) 72 { 73 $this->exportTable($table); 74 } 75 } 76 77 function exportTable($table) 78 { 79 $req = 'SELECT * FROM '.$this->con->escapeSystem($this->prefix.$table); 80 81 $this->export($table,$req); 82 } 83 84 function getTables() 85 { 86 $tables = array(); 87 foreach ($this->con->getTables() as $t) 88 { 89 if ($this->prefix) { 90 if (strpos($t,$this->prefix) === 0) { 91 $tables[] = $t; 92 } 93 } else { 94 $tables[] = $t; 95 } 96 } 97 98 return $tables; 99 } 100 101 function getLine(&$rs) 102 { 103 $l = array(); 104 foreach ($rs->columns() as $i => $c) { 105 $l[$i] = str_replace(array_keys($this->line_replacement),array_values($this->line_replacement),$rs->f($c)); 106 $l[$i] = '"'.$l[$i].'"'; 107 } 108 return implode(',',$l)."\n"; 109 } 110 } 111 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |