ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingขอคำแนะนำ php อ่่าน text file แล้ว insert to sql ค่ะ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ขอคำแนะนำ php อ่่าน text file แล้ว insert to sql ค่ะ  (อ่าน 1498 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
test_one
ก๊วนเสียว
*

พลังน้ำใจ: 3
ออฟไลน์ ออฟไลน์

กระทู้: 207



ดูรายละเอียด
« เมื่อ: 22 มกราคม 2013, 00:09:37 »

ขอคำแนะนำ php อ่่าน text file  แล้ว  insert to sql ค่ะ  คือ  text file เก็บที่ ไดร์ D แล้วจากนั้นหากใน  ไดร์ D  มีไฟล์ .txt  อยู่ ก็ insert ลงฐานข้อมูลค่ะไม่ทราบว่าต้องทำอย่างไรค่ะ อาจจะเก็บไฟล์นั้น ไว้อีก folder ค่ะ   ขอคำแนะนำหน่อยหรือตัวอย่าง หน่อยนะค่ะิ Lips Sealed
บันทึกการเข้า
UnLock UnlimiT
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 228
ออฟไลน์ ออฟไลน์

กระทู้: 1,899



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 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')");
บันทึกการเข้า

งดรับซื้อ google ads ครับ Smiley
test_one
ก๊วนเสียว
*

พลังน้ำใจ: 3
ออฟไลน์ ออฟไลน์

กระทู้: 207



ดูรายละเอียด
« ตอบ #2 เมื่อ: 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


รบกวนช่วยดูให้หน่อยนะค่ะ
บันทึกการเข้า
Queue
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 106
ออฟไลน์ ออฟไลน์

กระทู้: 4,296



ดูรายละเอียด เว็บไซต์
« ตอบ #3 เมื่อ: 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 ผิด ก็รหัสผ่านผิด



ตามนั้น แหะๆๆ
บันทึกการเข้า

test_one
ก๊วนเสียว
*

พลังน้ำใจ: 3
ออฟไลน์ ออฟไลน์

กระทู้: 207



ดูรายละเอียด
« ตอบ #4 เมื่อ: 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  ต้องทำไงอ่ะค่ะ แบบที่ละหลายบันทัดค่ะ รบกวนหน่อยนะค่ะ 
บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์