예제 #1
0
        while ($row = $rs->fetchRow()) {
            $values = array();
            foreach ($row as $key => $val) {
                if (is_null($val)) {
                    $values[] = "null";
                } elseif (is_numeric($val)) {
                    $values[] = $val;
                } else {
                    $values[] = "'" . mysql_escape_string($val) . "'";
                }
            }
            $insert = "insert into {$table} values(" . implode(',', $values) . ");";
            $theWriter->writeln($insert);
        }
    }
    $bak_file_name = $theWriter->getFilename();
    $bak_file_size = $theWriter->getFilesize();
}
//------------------------------------
class SqlWriter
{
    private $_sql = '';
    private $_fp;
    private $_filename;
    function __construct()
    {
        $backupFile = date('Ymd-His-') . mt_rand(1000, 9999) . ".sql";
        $this->_filename = $backupFile;
        $fp = fopen($backupFile, 'w+');
        if ($fp) {
            $this->_fp = $fp;