մϴ.
  PHP (EXCEL) о DB(database) ϱ ȣ : 561        ȸ : 452 ȸ
         : Ȳȫ 

 

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title> </title>
  5. </head>
  6. <body>
  7. <?php
  8. $conn = mysql_connect("ȣƮ ּ""""йȣ");
  9. $mysql = mysql_select_db("DB"$conn);
  10. mysql_query("set names utf8");
  11. require_once "Comn/reader.php";
  12. $data = new Spreadsheet_Excel_Reader();
  13. $data->setOutputEncoding("UTF-8//IGNORE");
  14. $data->read("sample_excel.xls")
  15. for ($i = 2$i <= $data->sheets[0]["numRows"]$i++) {
  16. $my_name = $data->sheets[0]["cells"][$i][1];
  17. $my_age = $data->sheets[0]["cells"][$i][2];
  18. $my_gender = $data->sheets[0]["cells"][$i][3];
  19. $my_phone = $data->sheets[0]["cells"][$i][4];
  20. $query = "insert into my_user (my_name,my_age,my_gender,my_phone) values ('{$my_name}','{$my_age}','{$my_gender}','{$my_phone}') ";
  21. $result = mysql_query($query$conn);
  22. }
  23. echo $my_name."<br>";
  24. echo $my_age."<br>";
  25. echo $my_gender."<br>";
  26. echo $my_phone;
  27. mysql_close($conn);
  28. ?>
  29. </body>
  30. </html>

 

ü ҽ ϴ . ׷ ϳϳ .

 

 

1. DB  .. 

$conn = mysql_connect("""""");
$mysql = mysql_select_db(""$conn);
mysql_query("set names utf8");     

 
2.PHP ̺귯 ε.
require_once "Comn/reader.php";
 
3.̺귯 Ǿ ִ ü Լ ̿ ʱ .
 
$data = new Spreadsheet_Excel_Reader();

$data->setOutputEncoding("UTF-8//IGNORE");

$data->read("sample_excel.xls");    
 
ο ڸ ݵ OUTPUTENcoding  read ռ ; Ѵ.
׸ read ǵ  ݵ   ÷ ־  Ѵ.
 
4. DB ڷ ϱ
 
 for ($i = 2$i <= $data->sheets[0]["numRows"]$i++) {

$my_name = $data->sheets[0]["cells"][$i][1];

$my_age = $data->sheets[0]["cells"][$i][2];

$my_gender = $data->sheets[0]["cells"][$i][3];

$my_phone = $data->sheets[0]["cells"][$i][4];

$query = "insert into my_user (my_name,my_age,my_gender,my_phone) values ('{$my_name}','{$my_age}','{$my_gender}','{$my_phone}') ";

$result = mysql_query($query$conn);
}
 
 
$data->sheets[0]["numRows"];  Ʈ ȯ ش.
 
÷   ˰, ÷ 3 4̴.
 
for ($i = 2;   .. $i 2 ߳ĸ,
 
1 ϸ ̸ ȣ ..  Һз ڱ о  ̴.
( 𸣸  ÷ε   open open)
 
׷ 2 Ͽ, ù° ϰ DB Ű ̴.
 
 
  ؿ  
 
echo $my_name."<br>";
echo $my_age."<br>";
echo $my_gender."<br>";
echo $my_phone;

mysql_close($conn);
 
Ҵ Ǵ  echo Ѱ̰,
 
۾ 'ݵ' DB Ŭ ־ Ѵ.

 

Comm/reader.php Ʒ Ʈ ٿ .

http://shonm.tistory.com/attachment/cfile26.uf@2067D03E4D4FABA426F0DB.zip

 

 

ó : http://blog.naver.com/87kks/40187215290



ó: https://codeghost.tistory.com/34 [] 

޸𳲱 ѱ 150 300 ̳
ۼ         н                  0 byte
[ñ] ۼϽ : 2021-11-26 19:32:49
Copyright(c) 2003 xirom all right reserved vol.3
Contact xirom@xirom.net form more information