dengan menampilkan data mahasiswa berdasarkan input nim,Program dibuat menggunakan teknik web service SOAP.
1.membuat server mahasiswa dengan coding di bawah ini dan di simpan dalam bentuk serverMahasiswa.php
| <?php | |
| require_once "lib/nusoap.php"; |
| $server = new soap_server(); |
| $server->configureWSDL('serverMahasiswa', 'urn:serverMahasiswa'); |
| $server->register('ambilnim', // method name |
| array('nim' => 'xsd:string'), // input parameters |
| array('return' => 'xsd:string'), // output parameters |
| 'urn:serverMahasiswa', // namespace |
| 'urn:serverMahasiswa#ambilnama', // soapaction |
| 'rpc', // style |
| 'encoded', // use |
| 'Says hello to the caller' // documentation |
| ); |
| function ambilnim($nim) { |
| include "koneksi.php"; |
| $hasil = mysqli_query($koneksi, "select * from siswa where nim =$nim"); |
| $data = mysqli_fetch_row($hasil); |
| $m = 'nim= '.$data[0].'nama= '.$data[1].'progdi= '.$data[2]; |
| return 'Hasil query ' .$m; |
| } |
| // $hasil = ambilnim(8); |
| // print_r($hasil); |
| // $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) |
| // ? $HTTP_RAW_POST_DATA : ''; |
| // $server->service($HTTP_RAW_POST_DATA); |
| @$server->service(file_get_contents("php://input")); |
2.langkah selanjutnya kita wajib membuat kategori dengan koding di bawah ini dan di simpan dengan entensi kategori.sql
CREATE TABLE IF NOT EXISTS `tbl_kategori` (
| |||||||
3.dan langkah senjunya membuat clayen untuk mengimputkan mahasiswa dengan koding di bawah ini dan di simpan dengan estensen ClientMahasiswa.php
<?php
| include "lib/nusoap.php"; | ||
| $wsdl ="http://localhost/kuliah/WebServis/soap-php/serverMahasiswa.php?wsdl"; |
| $client = new nusoap_client($wsdl,true); |
| // $parent = $_GET['id']; |
| // $response = $client->call('ambilnim',array('nim'=>$parent)); |
| // print_r($response); |
| $err = $client->getError(); |
| if ($err) { |
| // Display the error |
| echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; |
| // At this point, you know the call that follows will fail |
| } |
| $nim = $_GET['id']; |
| echo $nim; |
| $result = $client->call('ambilnim', array('nim'=>$nim)); |
| if ($client->fault) { |
| echo '<h2>Fault</h2><pre>'; |
| print_r($result); |
| echo '</pre>'; |
| } else { |
| // Check for errors |
| $err = $client->getError(); |
| if ($err) { |
| // Display the error |
| echo '<h2>Error</h2><pre>' . $err . '</pre>'; |
| } else { |
| // Display the result |
| echo '<h2>Result</h2><pre>'; |
| print_r($result); |
| echo '</pre>'; |
| } |
| } |
| echo '<h2>Request</h2>'; |
| echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>'; |
| echo '<h2>Response</h2>'; |
| echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>'; |
| // Display the debug messages |
| echo '<h2>Debug</h2>'; |
| echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>'; |
4. langkah selanjutnya adalah untuk menghubungkan semua nya kita bisa membuat koneksi dan dapat di simpan dengan estensen koneksi.php
<?php
| $koneksi = mysqli_connect('localhost',"root","","akademik"); |
5. dan untuk pengimputan nya dengan koding di bawah ini dan di simpan dengan input.php
<!DOCTYPE html>
| <html> |
| <head> |
| <title>Input Data</title> |
| </head> |
| <body> |
| <form action="" method="post"> |
| Nim<br> |
| <input type="text" name="nim"><br> |
| Nama<br> |
| <input type="text" name="nama"><br> |
| Alamat<br> |
| <input type="text" name="alamat"><br> |
| Progdi<br> |
| <input type="text" name="progdi"><br> |
| <br> |
| <input type="submit" name="submit" value="Save"><br> |
| </form> |
| <?php |
| include "koneksi.php"; |
| if (isset($_POST['submit'])) { |
| $nim = $_POST['nim']; |
| $nama =$_POST['nama']; |
| $alamat = $_POST['alamat']; |
| $progdi = $_POST['progdi']; |
| $result = mysqli_query($koneksi, "INSERT INTO siswa(nim,nama,alamat,progdi) VALUES('$nim','$nama','$alamat','$progdi')"); |
| $pesan= ""; |
| if ($result) { |
| $pesan = "Data Berhasil disimpan"; |
| header("location:ClientMahasiswa.php?id=$nim"); |
| }else{ |
| $pesan ="Data Gagal Disimpan"; |
| } |
| $response= array('pesan'=>$pesan , 'data'=>$_POST); |
| } |
| ?> |
| </body> |
sekian yang saya contoh kan tentang program php SOAP semoga bermanfaat untuk rekan rekan |