<?php
$file = fopen($_POST["bgUp"] , "rb");
$line_count = load_backup_sql($file);
fclose($file);
echo "lines read: ".$line_count;
function load_backup_sql($file) {
$line_count = 0;
$db_connection = db_connect();
mysql_select_db (db_name()) or exit();
$line_count = 0;
while (!feof($file)) {
$query = NULL;
while (!feof($file)) {
$query .= fgets($file);
}
if (NULL != $query) {
$line_count++;
mysql_query($query) or die("sql not successful: ".mysql_error()." query: ".$query);
}
}
return $line_count;
}
function db_name() {
return ("edocs");
}
function db_connect() {
$db_connection = mysql_connect("localhost", "root", "1234");
return $db_connection;
?>
อันนี้คือมันรับค่าจาก file upload มานะครับ ซึ่งมันก็รับมาอ่านได้ครับ แต่มันไม่เกบลง db อ่ะคับ
ไฟล์ backup หน้าตาเป็นแบบนี้คับ
Code
CREATE DATABASE `edocs` DEFAULT CHARACTER SET tis620 COLLATE tis620_thai_ci; USE `edocs`; CREATE TABLE `action` ( `Id` int(11) NOT NULL auto_increment,`list` int(4) NOT NULL,`action_code` char(5) default NULL,`action_name` varchar(255) default NULL, PRIMARY KEY (`Id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620 AUTO_INCREMENT=38 ;CREATE TABLE `comp` ( `comp_id` int(3) NOT NULL,`comp_name` varchar(6) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=tis620;CREATE TABLE `department` (`dept_id` int(3) NOT NULL,`dept_code` int(3) NOT NULL,`dept_name` varchar(100) NOT NULL,PRIMARY KEY (`dept_id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620;CREATE TABLE `division` (`Id` int(11) NOT NULL auto_increment,`list` int(4) NOT NULL,`division_code` char(5) default NULL,`division_name` varchar(255) default NULL,PRIMARY KEY (`Id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620 AUTO_INCREMENT=38 ;CREATE TABLE `document` (`doc_id` int(8) NOT NULL,`doc_tmpid` int(8) NOT NULL,`doc_code` varchar(25) NOT NULL,`subject_code` varchar(5) NOT NULL,`doc_subject` varchar(255) NOT NULL,`file1` varchar(8) NOT NULL,`dated` date NOT NULL default '0000-00-00',`from1` varchar(100) NOT NULL,`to1` varchar(100) NOT NULL,`day_in` date NOT NULL default '0000-00-00',`ref` varchar(100) NOT NULL,`subject` varchar(8) NOT NULL,`rsub` varchar(2) NOT NULL,`title` varchar(255) NOT NULL,`action` varchar(100) NOT NULL,`cir` varchar(100) NOT NULL,`fax_d` date NOT NULL default '0000-00-00',`cir_d` date NOT NULL default '0000-00-00',`ref_out` varchar(100) NOT NULL,`date_out` date NOT NULL default '0000-00-00',`date_due` date NOT NULL default '0000-00-00',`kpi_date` date NOT NULL default '0000-00-00',`status` varchar(2) NOT NULL,`status_date` date NOT NULL default '0000-00-00',`doc_file1` varchar(100) NOT NULL,`doc_file2` varchar(100) NOT NULL,`doc_file3` varchar(100) NOT NULL,`ps` text NOT NULL,`doc_accept` char(1) NOT NULL,`date_rec` date NOT NULL default '0000-00-00',`insert_by` varchar(100) NOT NULL,`insert_date` datetime NOT NULL default '0000-00-00 00:00:00',PRIMARY KEY (`doc_id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620;CREATE TABLE `document_tmp` (`doc_id` int(8) NOT NULL,`doc_tmpid` int(8) NOT NULL,`doc_code` varchar(25) NOT NULL,`subject_code` varchar(5) NOT NULL,`doc_subject` varchar(255) NOT NULL,`file1` varchar(8) NOT NULL,`dated` date NOT NULL default '0000-00-00',`from1` varchar(100) NOT NULL,`to1` varchar(100) NOT NULL,`day_in` date NOT NULL default '0000-00-00',`ref` varchar(100) NOT NULL,`subject` varchar(8) NOT NULL,`rsub` varchar(2) NOT NULL,`title` varchar(255) NOT NULL,`action` varchar(100) NOT NULL,`cir` varchar(100) NOT NULL,`fax_d` date NOT NULL default '0000-00-00',`cir_d` date NOT NULL default '0000-00-00',`ref_out` varchar(100) NOT NULL,`date_out` date NOT NULL default '0000-00-00',`date_due` date NOT NULL default '0000-00-00',`kpi_date` date NOT NULL default '0000-00-00',`status` varchar(2) NOT NULL,`doc_file1` varchar(100) NOT NULL,`doc_file2` varchar(100) NOT NULL,`doc_file3` varchar(100) NOT NULL,`ps` text NOT NULL,`doc_accept` char(1) NOT NULL,`date_rec` date NOT NULL default '0000-00-00',`add_status` varchar(10) NOT NULL,`insert_by` varchar(100) NOT NULL,`insert_date` datetime NOT NULL default '0000-00-00 00:00:00',PRIMARY KEY (`doc_id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620;CREATE TABLE `documentout` (`doco_id` int(8) NOT NULL,`doco_Tmpid` int(8) NOT NULL,`doc_date` date NOT NULL default '0000-00-00',`doc_from` varchar(100) NOT NULL,`doc_to` varchar(100) NOT NULL,`date_out` date NOT NULL default '0000-00-00',`date_receive` date NOT NULL default '0000-00-00',`ref` varchar(8) NOT NULL,`ref2` varchar(5) NOT NULL,`ref3` varchar(5) NOT NULL,`ref4` varchar(10) NOT NULL,`rsub` varchar(2) NOT NULL,`totalref` varchar(100) NOT NULL,`title` text NOT NULL,`date_req` date default '0000-00-00',`requester` varchar(20) NOT NULL,`cir` varchar(100) NOT NULL,`date_rec` date NOT NULL default '0000-00-00',`ref_in` varchar(100) NOT NULL,`doc_file1` varchar(100) NOT NULL,`doc_file2` varchar(100) NOT NULL,`doc_file3` varchar(100) NOT NULL,`ps` text NOT NULL,`doc_accept` char(2) NOT NULL,`insert_by` varchar(100) NOT NULL,`insert_date` datetime NOT NULL default '0000-00-00 00:00:00',PRIMARY KEY (`doco_id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620;CREATE TABLE `documentout_tmp` (`doco_id` int(8) NOT NULL,`doco_Tmpid` int(8) NOT NULL,`doc_date` date NOT NULL default '0000-00-00',`doc_from` varchar(100) NOT NULL,`doc_to` varchar(100) NOT NULL,`date_out` date NOT NULL default '0000-00-00',`date_receive` date NOT NULL default '0000-00-00',`ref` varchar(8) NOT NULL,`ref2` varchar(5) NOT NULL,`ref3` varchar(5) NOT NULL,`ref4` varchar(10) NOT NULL,`rsub` varchar(2) NOT NULL,`totalref` varchar(50) NOT NULL,`title` text NOT NULL,`date_req` date default '0000-00-00',`requester` varchar(20) NOT NULL,`cir` varchar(100) NOT NULL,`date_rec` date NOT NULL default '0000-00-00',`ref_in` varchar(100) NOT NULL,`doc_file1` varchar(100) NOT NULL,`doc_file2` varchar(100) NOT NULL,`doc_file3` varchar(100) NOT NULL,`ps` text NOT NULL,`doc_accept` char(2) NOT NULL,`add_status` varchar(20) NOT NULL,`insert_by` varchar(100) NOT NULL,`insert_date` datetime NOT NULL default '0000-00-00 00:00:00',PRIMARY KEY (`doco_id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620;CREATE TABLE `employee` (`id` int(5) NOT NULL auto_increment,`emp_id` int(5) NOT NULL,`emp_name` varchar(100) NOT NULL,`emp_email` varchar(100) NOT NULL,`emp_div` int(3) NOT NULL,`emp_dept` int(3) NOT NULL,`emp_user` varchar(30) NOT NULL,`emp_password` varchar(8) NOT NULL,`emp_role` int(2) NOT NULL,`emp_comp` int(2) NOT NULL,`emp_status` char(1) NOT NULL,`insert_by` varchar(100) NOT NULL,`insert_date` date NOT NULL default '0000-00-00',PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620 AUTO_INCREMENT=7 ;CREATE TABLE `role` (`role_id` int(3) NOT NULL,`role_name` varchar(50) NOT NULL,PRIMARY KEY (`role_id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620;CREATE TABLE `statusfor` (`status_id` int(5) NOT NULL,`status_code` varchar(5) NOT NULL,`status_detail` varchar(50) NOT NULL,PRIMARY KEY (`status_id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620;CREATE TABLE `subject` (`subject_id` int(5) NOT NULL,`subject_code` varchar(5) NOT NULL,`subject_detail` varchar(255) NOT NULL,PRIMARY KEY (`subject_id`)) ENGINE=MyISAM DEFAULT CHARSET=tis620; USE `edocs`; INSERT INTO action VALUES('1', '11', '80', 'สำนักกรรมการผู้จัดการ');INSERT INTO action VALUES('2', '12', '90', 'สำนักตรวจสอบภายใน');INSERT INTO action VALUES('3', '5', '10', 'ฝ่ายบริหารทั่วไป');INSERT INTO action VALUES('4', '6', '20', 'ฝ่ายการเงิน');INSERT INTO action VALUES('5', '7', '30', 'ฝ่ายรายได้ค่าผ่านทาง');INSERT INTO action VALUES('6', '8', '40', 'ฝ่ายก่อสร้างและบำรุงรักษา');INSERT INTO action VALUES('7', '9', '60', 'ฝ่ายวางแผนและพัฒนา');INSERT INTO action VALUES('8', '10', '70', 'ฝ่ายการจราจร');INSERT INTO action VALUES('9', '1', 'MD', 'MD');INSERT INTO action VALUES('10', '2', 'AMD1', 'AMD1');INSERT INTO action VALUES('11', '3', 'AMD2', 'AMD2');INSERT INTO action VALUES('12', '4', 'AMD3', 'AMD3');INSERT INTO action VALUES('13', '13', '40d', '40d');INSERT INTO action VALUES('14', '14', '60d', '60d');INSERT INTO comp VALUES('1', 'BECL');INSERT INTO comp VALUES('2', 'NECL').......(insert จนครบอะคับ เยอะมาก)