ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: test_one ที่ 22 มกราคม 2013, 00:09:37



หัวข้อ: ขอคำแนะนำ php อ่่าน text file แล้ว insert to sql ค่ะ
เริ่มหัวข้อโดย: test_one ที่ 22 มกราคม 2013, 00:09:37
ขอคำแนะนำ php อ่่าน text file  แล้ว  insert to sql ค่ะ  คือ  text file เก็บที่ ไดร์ D แล้วจากนั้นหากใน  ไดร์ D  มีไฟล์ .txt  อยู่ ก็ insert ลงฐานข้อมูลค่ะไม่ทราบว่าต้องทำอย่างไรค่ะ อาจจะเก็บไฟล์นั้น ไว้อีก folder ค่ะ   ขอคำแนะนำหน่อยหรือตัวอย่าง หน่อยนะค่ะิ :-X


หัวข้อ: Re: ขอคำแนะนำ php อ่่าน text file แล้ว insert to sql ค่ะ
เริ่มหัวข้อโดย: UnLock UnlimiT ที่ 22 มกราคม 2013, 00:15:55
อ้างถึง
$youdata = file_get_contents("data/data.txt");
$youdata = preg_replace('/\$(\w+)/e', '$GLOBALS["\\1"]', $youdata );
$youdata = mysql_real_escape_string("$youdata");
mysql_query("INSERT...... value ('$youdata')");


หัวข้อ: Re: ขอคำแนะนำ php อ่่าน text file แล้ว insert to sql ค่ะ
เริ่มหัวข้อโดย: test_one ที่ 13 กุมภาพันธ์ 2013, 01:28:05
อ้างถึง
$youdata = file_get_contents("data/data.txt");
$youdata = preg_replace('/\$(\w+)/e', '$GLOBALS["\\1"]', $youdata );
$youdata = mysql_real_escape_string("$youdata");
mysql_query("INSERT...... value ('$youdata')");

<?
$data = date("Ymd");
$youdata = file_get_contents("../txt/".$data.".txt");
$youdata = preg_replace('/\$(\w+)/e', '$GLOBALS["\\1"]', $youdata );
$youdata = mysql_real_escape_string("$youdata");
mysql_query("INSERT INTO  board_test (name , detail) VALUES ('".$objArr[0]."','".$objArr[1]."')");
?>

ทำแบบนี้ไปค่ะ แล้ว error   ค่ะ
Warning: file_get_contents(../txt/20130213.txt) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\board\frm_get_file.php on line 3

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\board\frm_get_file.php on line 5

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\board\frm_get_file.php on line 5

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\board\frm_get_file.php on line 6

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in
C:\xampp\htdocs\board\frm_get_file.php on line 6


รบกวนช่วยดูให้หน่อยนะค่ะ


หัวข้อ: Re: ขอคำแนะนำ php อ่่าน text file แล้ว insert to sql ค่ะ
เริ่มหัวข้อโดย: Queue ที่ 13 กุมภาพันธ์ 2013, 01:54:26
อ้างถึง
ทำแบบนี้ไปค่ะ แล้ว error   ค่ะ
Warning: file_get_contents(../txt/20130213.txt) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\board\frm_get_file.php on line 3
หาไฟล์ ../txt/20130213.txt ไม่เจอ หรือไม่มีสิทธิ์อ่าน น่าจะหาไม่เจอมากกว่า


อ้างถึง
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\board\frm_get_file.php on line 5
ติดต่อ Db ไม่ได้ ไม่ user ผิด ก็รหัสผ่านผิด

อ้างถึง
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\board\frm_get_file.php on line 5
จากข้อแรก หาไฟล์ไม่เจอ หรือไม่มีสิทธิ์อ่าน ทำให้มาทำงานต่อบรรทัดนี้ไม่ได้ เพราะตัวแปลไม่มีค่า


อ้างถึง
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\board\frm_get_file.php on line 6
ติดต่อ Db ไม่ได้ ไม่ user ผิด ก็รหัสผ่านผิด



ตามนั้น แหะๆๆ


หัวข้อ: Re: ขอคำแนะนำ php อ่่าน text file แล้ว insert to sql ค่ะ
เริ่มหัวข้อโดย: test_one ที่ 13 กุมภาพันธ์ 2013, 08:13:34
อ้างถึง
ทำแบบนี้ไปค่ะ แล้ว error   ค่ะ
Warning: file_get_contents(../txt/20130213.txt) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\board\frm_get_file.php on line 3
หาไฟล์ ../txt/20130213.txt ไม่เจอ หรือไม่มีสิทธิ์อ่าน น่าจะหาไม่เจอมากกว่า


อ้างถึง
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\board\frm_get_file.php on line 5
ติดต่อ Db ไม่ได้ ไม่ user ผิด ก็รหัสผ่านผิด

อ้างถึง
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\board\frm_get_file.php on line 5
จากข้อแรก หาไฟล์ไม่เจอ หรือไม่มีสิทธิ์อ่าน ทำให้มาทำงานต่อบรรทัดนี้ไม่ได้ เพราะตัวแปลไม่มีค่า


อ้างถึง
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\board\frm_get_file.php on line 6
ติดต่อ Db ไม่ได้ ไม่ user ผิด ก็รหัสผ่านผิด



ตามนั้น แหะๆๆ

require("connect.php");

$data = date("Ymd");
$ftpUri = "../txt/".$file;
$youdata = @file_get_contents('../txt/'.$data.'.txt', true);
$youdata = preg_match('/\$(\w+)/e', '$ftpUri["\\1"]', $youdata );
$youdata = mysql_real_escape_string("$youdata");


แล้วจะ insert  ข้อมูลจาก .txt  ต้องทำไงอ่ะค่ะ แบบที่ละหลายบันทัดค่ะ รบกวนหน่อยนะค่ะ