This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//INISIALISASI | |
$id_perkiraan_array = []; | |
$kode_perkiraan_array = []; | |
//INSERT | |
array_push($id_perkiraan_array, $id_perkiraan); | |
array_push($kode_perkiraan_array, $kode_perkiraan); | |
//MENCARI ID_PERKIRAAN DARI ARRAY ID BERDASARKAN PARAMETER KODE_PERKIRAAN | |
if (array_search('KODE PERKIRAAN YG DI DICARI', $kode_perkiraan_array) !== false) { | |
$id_perkiraan_PATOKAN = $id_perkiraan_array[array_search('KODE PERKIRAAN YG DI DICARI', $kode_perkiraan_array)]; | |
} else { | |
$id_perkiraan_PATOKAN = null; | |
} | |
try { | |
$db->beginTransaction(); | |
$id_barang_PATOKAN_ARRAY = []; | |
$nama_barang_PATOKAN_ARRAY = []; | |
$stmt = $db->prepare("SELECT * FROM barang"); | |
$stmt->execute(); | |
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); | |
$total_rows = count($rows); //BANYAK DATA YANG BERHASIL DI SELECT | |
//$total_rows = $stmt->rowCount(); //BANYAK DATA YANG BERHASIL DI SIMPAN/UPDATE/DELETE | |
for ($i = 0; $i < $total_rows; $i++) { | |
$id_barang = $rows[$i]["id_barang"]; | |
$nama_barang = $rows[$i]["nama_barang"]; | |
array_push($id_barang_PATOKAN_ARRAY, $id_barang); | |
array_push($nama_barang_PATOKAN_ARRAY, $nama_barang); | |
} | |
if($total_rows == 0) { | |
throw new PDOException("TIDAK ADA DATA"); | |
} | |
$db->commit(); | |
echo '[{"hasil":1, "pesan_hasil":"SUKSES"}]'; | |
} catch (PDOException $ex) { | |
$db->rollBack(); | |
echo '[{"hasil":0, "pesan_hasil":"ERROR: ' . $ex->getMessage() . '"}]'; | |
} | |
?> |