Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $file = "c:\tes.txt";
- if(!(file_exists($file)))
- {
- $handle = fopen($filecontoh , 'w') or die('Gagal membuka: '.$filecontoh );
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='test';
- $con = mysql_connect($dbhost,$dbuser,$dbpass);
- $sb= mysql_select_db($dbname,$con);
- $query = 'SELECT * FROM detail';
- if($hasil = mysql_query($query))
- {
- if(mysql_num_rows($hasil)>0)
- {
- $content='';
- while($data=mysql_fetch_array($hasil))
- {
- $content.=str_pad($data['id'],2,STR_PAD_LEFT)
- .str_pad($data['nama'],25,STR_PAD_LEFT)
- .str_pad($data['alamat'],25,STR_PAD_LEFT)
- .str_pad($data['telp'],12,STR_PAD_LEFT)."\n";
- }
- fwrite($handle, $content);
- fclose($file_anyar);
- echo "File berhasil dibuat";
- }
- else
- {
- echo "tidak ditemukan data di tabel";
- }
- }
- else
- {
- echo "query data tidak berhasil";
- }
- }
- else
- {
- echo "File tidak jadi dibuat karena file $file sudah ada";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement