|
 |
|
อ่านค่าจาก csv ที่ละหลายบันทัด แล้ว insert ลงฐานข้อมูลไม่ได้ค่ะ |
|
 |
|
|
 |
 |
|
ลองดูแบบนี้ ซิครับใกล้เคียงกันมั้ย
<?
//$FILE = fopen( "testcsv.csv", "r");
//$FILE = fopen( "id.csv", "r");
//$FILE = fopen( "u.csv", "r");
$FILE = fopen( "z.csv", "r");
$data = fgetcsv( $FILE , 1024 );
$i=1;
do
{
if ($i == 1){
$data = fgetcsv( $FILE , 1024 );
$i++;
}
else{
$host="localhost";
$user="root";
$password="kekekekeke";
$dbname="xxxx";
$conetion=mysql_connect($host,$user,$password) or die("อะไรว่ะ");
$db=mysql_select_db($dbname) or die("?????? DB ??????");
mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client='tis620'");
mysql_query("SET character_set_connection='tis620'");
mysql_query("collation_connection = tis620_thai_ci");
mysql_query("collation_database = tis620_thai_ci");
mysql_query("collation_server = tis620_thai_ci");
//$sql="INSERT INTO tb_student (id,card,pass,titleName,firstName,lastName,major,faculty,institute,uProvince,locate,status) VALUES ('$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[9]', '$data[10]', '$data[11]');";
//$sql="INSERT INTO tb_contract (id_c) VALUES ('$data[0]');";
//$sql="INSERT INTO tb_detail (id_d) VALUES ('$data[0]');";
//$sql="INSERT INTO tb_order (id_o) VALUES ('$data[0]');";
//$sql="INSERT INTO tb_stitute (id_s,uCode,uName) VALUES ('$data[0]', '$data[1]', '$data[2]');";
$sql="INSERT INTO tb_zone (id_z,uName,zName,zone) VALUES ('$data[0]', '$data[1]', '$data[2]', '$data[3]');";
$dbquery=mysql_db_query($dbname,$sql);
mysql_close();
$data = fgetcsv( $FILE , 1024 );
$i++;
}}while ( !feof( $FILE ) );
echo "ผ่านว่ะ";
?>
|
 |
 |
 |
 |
Date :
2013-02-13 10:29:19 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|