Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username="root";
- $password="";
- $database="bljr_makanan";
- mysql_connect("localhost",$username,$password);
- @mysql_select_db ($database) or die( "Unable to select database");
- $file = "./sampel_data.tsv";
- $fileHandle = fopen($file,'r') or die("error opening file");
- while (($data = fgets($fileHandle,4096))!== false){
- $produk = explode(",",$data);
- $query = "INSERT INTO induk_produk(sn,produk_name,kategori) VALUES ('".$produk[0]."','".$produk[1]."','".$produk[2]."')";
- mysql_query($query);
- $bahan = explode(";",$produk[3]);
- for($i=0; $i<count($bahan); $i++){
- $query_bahan = "INSERT INTO induk_bahan(bahan_name) VALUES ('".$bahan[$i]."')";
- mysql_query($query_bahan);
- $query_bahan = "INSERT INTO relasi_produk_bahan(produk_id,bahan_id) select distinct sn, bahan_id from induk_produk,induk_bahan where sn='$produk[0]' and bahan_name = '$bahan[$i]'";
- mysql_query($query_bahan);
- # echo $query_bahan;
- }
- }
- fclose($fileHandle);
- mysql_close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement