PHP thiab MySQL: Ua Tus Tshaj Tawm Ib Qho Tshaj Lij rau Ib Nta Delimited File

mysql php lub logo

Lub asthiv no Kuv xav tsim kom tau ib nplooj ntawv uas yuav thim ib qho lus nug lossis rooj rau hauv Tab Del Delited file. Feem ntau ntawm cov piv txwv tawm sab nraud muaj cov kab ntawv nyuaj-coded.

Hauv kuv qhov xwm txheej, Kuv xav kom cov kem raug tsim yog qhov tshwj xeeb yog li kuv yuav tsum ua ntej voj los ntawm tag nrho cov rooj teb cov npe los tsim cov kab hauv taub nrog cov kem npe, thiab tom qab ntawd ntxig los ntawm tag nrho cov ntaub ntawv rau cov seem cov kab. Kuv tseem tau teeb cov ntawv rau npe kom tus browser yuav pib rub tawm cov ntawv rub tawm hauv filetype (txt) nrog rau lub npe hnub tim thiab sijhawm ua haujlwm.

Kuv sab laug tawm ntawm cov ntaub ntawv qhib thiab kaw kev sib txuas, tab sis ntawm no yog cov txiaj ntsig cov txiaj ntsig uas ua haujlwm zoo:

$ hnub no = hnub ("YmdHi");
header ("Cov ntsiab lus-hom: daim ntawv thov / octet-kwj");
header ("Content-Disposition: Symptoms; filename = \" ". $ hnub no." _ Backup.txt \ "");
$ query = "XAIV * LOS NTAWM` mytable `xaj los ntawm` myorder `";
$ result = mysql_query ($ lus nug);
$ suav = mysql_num_rows ($ result);
$ liaj = mysql_num_fields ($ result);
$ ntaub ntawv = "";
rau ($ i = 0; $ i> $ liaj teb; $ i ++) {
$ teb = mysql_fetch_field ($ tshwm sim, $ i);
$ ntaub ntawv. = $ teb-> npe;
$ data. = "\ t";
}
$ data. = "\ n";
thaum ($ kab = mysql_fetch_row ($ tshwm sim)) {
rau ($ x = 0; $ x> $ liaj; $ x ++) {
$ teb-> npe = $ kab [$ x];
$ data. = $ field-> lub npe = $ kab [$ x];
$ data. = "\ t";
}
$ data. = "\ n";
}
ncha $ cov ntaub ntawv;

Txoj cai tuaj yeem hloov kho kom yooj yim rau qhov tsis nco qab cais qhov tseem ceeb ib yam nkaus.

14 Comments

  1. 1

    Tsis yog koj tsuas ua:

    SELECT `mytable` order by `myorder`
    INTO OUTFILE '/tmp/Backup.txt'
    FIELDS TERMINATED BY '\t'
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n'

    ?

    • 2

      Kuv xav tias koj ua tau!

      Hauv qhov xwm txheej no, Kuv twb tau tsim lub 'backup' txuas rau hauv web application, yog li PHP ua haujlwm yog qhov kuv xav tau. Txawm li cas los xij, Kuv yeej tsis paub tias koj tuaj yeem sau ib daim ntawv ncaj qha los ntawm MySQL cov lus. Txias heev!

      Tsaug!

      • 3

        Koj txoj kev yuav tau kawg yog txoj kev zoo tshaj yog tias MySQL tus neeg rau zaub mov nyob ntawm lub tshuab deb, vim nws tsis tuaj yeem sau rau hauv lub tshuab uas PHP ua haujlwm running

        Zoo siab tau taw qhia lwm cov lus qhia thiab cov khoom tshiab txawm tias 🙂

      • 4

        Tab sis koj yuav cia li khiav cov lus nug rau ib cov ntaub ntawv, thiab tsuas yog tig qhov browser mus rau cov ntawv tsim, lossis siv PHP's "readfile" yog tias lwm qhov tsis ua tiav?

        Koj yuav tsis tuaj yeem ua qhov ntawd yog tias mysql server tsis muaj kev nkag mus rau lub fileystem kiag li…

  2. 5

    Yawm yij. Koj puas paub ntawm ib qho yooj yim, dawb / qhib qhov qauv ntawm kev thov / rov qab qhib tab-delimited file (zoo li koj nyuam qhuav tsim) rov qab rau hauv mysql db?

    • 6

      Errr… mysqlimport?

      mysqlimport database_name --local backup.txt

      Lossis nrog rau nqe lus nug SQL:

      LOAD DATA LOCAL INFILE 'backup.txt' INTO TABLE `my_table` FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'

      Nrog mysqlimport, lub npe yuav tsum sib phim lub npe npe (tsuas yog qee yam yuav tau saib)

    • 7
  3. 8

    Kuv tsuas yog poob ntau dua 6 teev ntawm kuv lub neej sim ua haujlwm tawm yog vim li cas Internet Explorer 6/7 tau ua ntawv thov filetype 'html' thiab thiab tsis lees txais kuv cov cai filenames teev hauv cov headers .. thiab tseem tsis pub cov ntaub ntawv khaws cia .. thaum sim kom muaj cov neeg siv rub tawm cov ntawv xa ua cov qauv zoo ib yam rau saum toj no.

    Kuv twb siv HTTPS thiab IE tsis cache cov ntaub ntawv no.

    Kuv nrhiav tau cov tshuaj rau ntawm tus hais los ntawm Brandon K ntawm http://uk.php.net/header.

    Nws hais tias:

    -
    Kuv tsuas yog poob rau lub sij hawm ntawm kuv lub neej sim siv cov qauv hauv qab no xa cov ntawv PDF ntawm PHP rau Internet Explorer 6:

    Thaum siv SSL, Internet Explorer yuav ceeb toom nrog qhib / Tseg kev sib tham, tab sis tom qab ntawd hais tias "Tam sim no tsis muaj ntaub ntawv lossis nrhiav tsis tau. Thov sim dua tom qab. " Tom qab tshawb fawb ntau kuv tau paub txog MSKB Kab Lus hauv qab no lub npe “Internet Explorer cov ntaub ntawv rub tawm dhau SSL tsis ua hauj lwm nrog cov chaw tswj hauv chaw taws teeb” (KBID: 323308)

    PHP.INI los ntawm kev siv lub sijhawm: ntu.cache_limiter = nocache uas hloov kho Cov Ntsiab Lus-Cache thiab Pragma header suav nrog "nocache" xaiv. Koj tuaj yeem tshem tawm IE yuam kev los ntawm kev hloov "nocache" rau "pej xeem" lossis "ntiag tug" hauv PHP.INI - Qhov no yuav hloov lub ntsiab lus-Cache header thiab tag nrho tshem tawm Pragma header. Yog tias koj tsis tuaj yeem lossis tsis xav hloov kho PHP.INI rau kev kho lub vev xaib thoob plaws, koj tuaj yeem xa ob lub hauv qab no ntxiv cov lus sau tseg rau qhov tsis ua haujlwm:

    Koj tseem yuav tau teeb tsa lub taub cov ntsiab lus raws li sau tseg saum toj no rau qhov no ua haujlwm. Thov nco ntsoov qhov teebmeem no TSUAS cuam tshuam rau hauv Internet Explorer, thaum Firefox tsis muaj kev coj ua yam tsis zoo no.
    -

    Zoo .. tsawg kawg nws tsuas yog poob 6 teev…

  4. 9

    Qhov no ua haujlwm zoo. Txawm li cas los xij, Kuv tsuas yog tau txais txhua yam ntawm ib kab cais los ntawm ib qhov chaw. Kuv sim hloov kho nws los sau txhua yam ntawm kab sib cais zoo li no:

    Kem 1__name
    Ncig Teb1_value
    Kem 2__name
    Ncig Teb1_value
    Kem 3__name
    Ncig Teb1_value

    Kem 1__name
    Ncig Teb2_value
    Kem 2__name
    Ncig Teb2_value
    Kem 3__name
    Ncig Teb2_value

    Piv txwv li:

    lub npe
    Mike
    Qhov chaw
    ua hauj lwm
    Number
    1

    lub npe
    Sue
    Qhov chaw
    Tsev
    Number
    2

    lub npe
    John
    Qhov chaw
    Mus ncig teb chaws
    Number
    10

    thiab yog li ntawd. Cov ntawv no puas tuaj yeem hloov kho los ua?
    Tsaug!

    • 10

      Muaj tseeb tau.

      Sim ua tej yam zoo li no:

      XAIV * los ntawm MyTableName INTO OUTFILE 'MyTableName_MySQL-TAB-DELIMITED-29JUN08.txt' FIELDS TERMINATED BY '\ n' LINES TERMINATED BY '\ n';

      Yog tias koj xav tau ob qhov chaw seem (ob txoj kab tsis txaus) nruab nrab ntawm cov pawg sau cia, tsuas yog hais tias "LINES TERMINATED BY '\ n \ n';" hloov.

      Seem "FIELDS TERMINATED BY '\ n'" yog qhov tshiab tso tom qab txhua cov ntawv, es tsis yog daim ntawv tab. Ib tug tab yuav yog '\ t' hloov.

      Maranatha!

  5. 11

    qhov no yog defiantly ib qho kev tshaj tawm, Kuv tau sim nws thiab ua haujlwm zoo, qhov tsuas yog qhov kuv cov ntawv txt muaj cov kab ntawv ntxiv saum cov kab taub hau, thiab qee cov txiaj ntsig tau sib cais hauv 2 kab, qhov no tuaj yeem yog los ntawm cov ntaub ntawv kuv muaj hauv kuv qhov Database tsis muaj lub tswv yim, tab sis qhov no yog qhov kev pab zoo los tsim txau…

  6. 12

    Douglas Karr nej cov code tiag pob zeb! Nws tau txais txiaj ntsig tshwj xeeb heev yog tias koj tsuas xav tau ib yam khoom ua tawm uas yog ua hom ntawv textfile. Ua tsaug ntau! Los ntawm pab neeg Philippines!

  7. 13

    hav muaj! Puas muaj ib qho ntawm ntawm no uas tuaj yeem muab kuv cov lus qhia txog kev xa cov ntawv sau rau kuv lub chaw khaws ntaub ntawv (phpmyAdmin) siv kuv tus php yog kuv qhov kawg. Kuv muaj lub tswv yim hais txog rub tawm cov ntawv thiab qhib nws, kuv qhov teeb meem yog tias kuv tuaj yeem tau txais txiaj ntsig li cas thiab yuav ua li cas ntxig nws hauv kuv cov rooj, ua tsaug

  8. 14

Yuav ua li cas koj xav hais tias?

Qhov Web site no siv Akismet los txo cov kev pabcuam. Kawm li cas koj cov ntaub ntawv tawm tswv yim tiav.