Select into Outfile ...

Bella · Oct 8, 2012
SELECT tb_tes.tgl as tgl,
tb_tes.mem_id as mem_id,
tb_tes.jml as tes_jml,
tb_tes.jml-sum( tb_mem_2.jml_aml ) as tambah,
tb_tes.jml=sum( tb_mem_2.jml_aml ) as sama_
FROM tb_tes
LEFT JOIN tb_mem_2
ON tb_tes.mem_id = tb_mem_2.mem_id
GROUP BY tb_tes.tgl, tb_tes.ref_id
INTO OUTFILE 'C:\\tes.txt'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY ''
LINES TERMINATED BY '\r\n'

kalau dijalan pada phpmyadmin tidak ada masalah,
file tes.txt ada pada drive C:\. namun kalau pada php,
kok nggak ada reaksi apa-apa yah mas ? error nggak ada,
apa pun nggak ada. :(

phpnya kayak gini :
<?php
require_once( '../opendb.php' );

$trans = "SELECT tb_tes.tgl as tgl,
tb_tes.mem_id as mem_id,
tb_tes.jml as tes_jml,
tb_tes.jml-sum( tb_mem_2.jml_aml ) as tambah,
tb_tes.jml=sum( tb_mem_2.jml_aml ) as sama_
FROM tb_tes
LEFT JOIN tb_mem_2
ON tb_tes.mem_id = tb_mem_2.mem_id
GROUP BY tb_tes.tgl, tb_tes.ref_id
INTO OUTFILE '/coba/tes.txt'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY ''
LINES TERMINATED BY '\r\n'";

$hasil = mysql_query( $trans );
?>

mohon bantuannya ya mas...
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Oct 8, 2012 · 0 Suka · 0 Tidak Suka
coba ganti
$trans = "SELECT tb_tes.tgl as tgl,
tb_tes.mem_id as mem_id,
tb_tes.jml as tes_jml,
tb_tes.jml-sum( tb_mem_2.jml_aml ) as tambah,
tb_tes.jml=sum( tb_mem_2.jml_aml ) as sama_
FROM tb_tes
LEFT JOIN tb_mem_2
ON tb_tes.mem_id = tb_mem_2.mem_id
GROUP BY tb_tes.tgl, tb_tes.ref_id
INTO OUTFILE 'C:\\tes.txt'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY ''
LINES TERMINATED BY '\r\n'";

jika berhasil maka INTO OUTFILE harus berupa path absolute.

Sebagai catatan saja, biasanya hosting hosting tidak mengijikan eksekusi INTO OUTFILE
0
Loading...
Bella · Oct 8, 2012 · 0 Suka · 0 Tidak Suka
Tetep aja mas, gak bisa...
mas, sy nyoba create view dari phpmyadmin
kayak gini
CREATE ALGORITHM = UNDEFINED VIEW v_tmp_mem AS SELECT tb_tes.tgl as tgl,
tb_tes.mem_id as mem_id,
tb_tes.jml as tes_jml,
tb_tes.jml-sum( tb_mem_2.jml_aml ) as tambah,
tb_tes.jml=sum( tb_mem_2.jml_aml ) as sama_
FROM tb_tes
LEFT JOIN tb_mem_2
ON tb_tes.mem_id = tb_mem_2.mem_id
GROUP BY tb_tes.tgl, tb_tes.ref_id

cuma, syntax di php kayak gimana ya mas ?
dah puyeng mas, nyoba ga bisa" :O:(
mohon petunjuknya mas ya ....
0
Loading...
Ellyx Christian · Oct 8, 2012 · 0 Suka · 0 Tidak Suka
waduh bingung ne, yang mana ini ditanyakan?
0
Loading...
Bella · Oct 8, 2012 · 0 Suka · 0 Tidak Suka
yang ini mas ...
    CREATE ALGORITHM = UNDEFINED VIEW v_tmp_mem AS SELECT tb_tes.tgl AS tgl,
    tb_tes.mem_id AS mem_id,
    tb_tes.jml AS tes_jml,
    tb_tes.jml-SUM( tb_mem_2.jml_aml ) AS tambah,
    tb_tes.jml=SUM( tb_mem_2.jml_aml ) AS sama_
    FROM tb_tes
    LEFT JOIN tb_mem_2
    ON tb_tes.mem_id = tb_mem_2.mem_id
    GROUP BY tb_tes.tgl, tb_tes.ref_id
kalau d php kayak gimana mas ?
0
Loading...
Bella · Oct 8, 2012 · 0 Suka · 0 Tidak Suka
maskud saya, penulisan kode php kayak gimana
kalau querynya kayak itu
0
Loading...
Ellyx Christian · Oct 8, 2012 · 0 Suka · 0 Tidak Suka
sama seperti biasa
<?php
mysql_query("CREATE ALGORITHM = UNDEFINED VIEW v_tmp_mem AS SELECT tb_tes.tgl AS tgl,
tb_tes.mem_id AS mem_id,
tb_tes.jml AS tes_jml,
tb_tes.jml-SUM( tb_mem_2.jml_aml ) AS tambah,
tb_tes.jml=SUM( tb_mem_2.jml_aml ) AS sama_
FROM tb_tes
LEFT JOIN tb_mem_2
ON tb_tes.mem_id = tb_mem_2.mem_id
GROUP BY tb_tes.tgl, tb_tes.ref_id");
?>
Tapi ingat, view itu dibuat sekali bukan berkali kali.
0
Loading...
Bella · Oct 8, 2012 · 0 Suka · 0 Tidak Suka
ok mas, thanks ya tak coba dulu...
0
Loading...
Bella · Oct 8, 2012 · 0 Suka · 0 Tidak Suka
oh ya mas, gimana caranya nampilan pesen,
jika file view 'v_tmp_mem' tersebut sudah ada/terbetuk
thanks sebelum dan sesudahnya.
0
Loading...
Ellyx Christian · Oct 9, 2012 · 0 Suka · 0 Tidak Suka
<?php
if(mysql_query("select 1 from v_tmp_mem")){
echo "View sudah ada";
}