Created
June 2, 2021 14:05
-
-
Save umarhadi/383f0b4723472b48c0360235520c3be9 to your computer and use it in GitHub Desktop.
soapServer for Server 1
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 | |
/********************************************************** | |
* PHP SOAP - How to create a SOAP Server and a SOAP Client | |
*******************************************************/ | |
require_once('../adodb5/adodb.inc.php'); | |
require_once('../adodb5/adodb-active-record.inc.php'); | |
//koneksi ke database | |
$db = NewADOConnection('mysqli'); | |
$db->Connect('localhost', 'root', 'bAHGrXUmPMu1', 'soap_umar'); | |
class Crud | |
{ | |
//methode tambah data | |
function tambahData($nim, $nama, $alamat) | |
{ | |
$mhs = new Mahasiswa; | |
$mhs->nim = $nim; | |
$mhs->nama = $nama; | |
$mhs->alamat = $alamat; | |
if ($mhs->save() == 1) { | |
return "Berhasil di simpan"; | |
} else | |
return "Ada error, Gagal Menyimpan"; | |
} | |
// methode updateData | |
function updateData($nim, $nama, $alamat) | |
{ | |
$mhs = new ADOdb_Active_Record("mahasiswa"); | |
$mhs->nim = $nim; | |
$mhs->nama = $nama; | |
$mhs->alamat = $alamat; | |
$ok = $mhs->replace(); // 0=failure, 1=update, 2=insert | |
if ($ok == 1) | |
return "Berhasil diubah"; | |
else | |
return "gagal di ubah"; | |
} | |
//methode baca data | |
function bacaData() | |
{ | |
$db = NewADOConnection('mysqli'); | |
$db->Connect('localhost', 'root', 'bAHGrXUmPMu1', 'soap_umar'); | |
$rs = $db->Execute("SELECT * FROM mahasiswa "); | |
$result = $rs->GetArray(); | |
foreach ($result as $row => $value) { | |
$return_value[] = array( | |
'nim' => $value['nim'], | |
'nama' => $value['nama'], | |
'alamat' => $value['alamat'] | |
); | |
} | |
return $return_value; | |
} | |
//methode baca dan mengubah data | |
function bacaUbah($nim) | |
{ | |
$db = NewADOConnection('mysqli'); | |
$db->Connect('localhost', 'root', 'bAHGrXUmPMu1', 'soap_umar'); | |
$rs = $db->Execute("SELECT * FROM mahasiswa WHERE nim='" . $nim . "'"); | |
$result = $rs->GetArray(); | |
foreach ($result as $row => $value) { | |
$return_value[] = array( | |
'nim' => $value['nim'], | |
'nama' => $value['nama'], | |
'alamat' => $value['alamat'] | |
); | |
} | |
return $return_value; | |
} | |
//methode hapus data | |
function hapusData($nim) | |
{ | |
$db = NewADOConnection('mysqli'); | |
$db->Connect('localhost', 'root', 'bAHGrXUmPMu1', 'soap_umar'); | |
$rs = $db->Execute("DELETE FROM mahasiswa WHERE nim='" . $nim . "'"); | |
if (!$rs) { | |
return "Data tidak berhasil dihapus"; | |
} else | |
return "Data berhasil dihapus"; | |
} | |
} | |
ADOdb_Active_Record::SetDatabaseAdapter($db, 'mConnection'); | |
// menciptakan kelas Mahasiswa ke tabel mahasiswa | |
class Mahasiswa extends ADOdb_Active_Record | |
{ | |
public $_dbat = 'mConnection'; | |
public $_table = 'mahasiswa'; | |
} | |
//when in non-wsdl mode the uri option must be specified | |
$options = array('uri' => 'https://server.umarhadi.xyz/soap'); | |
//create a new SOAP server | |
$server = new SoapServer(NULL, $options); | |
//attach the API class to the SOAP Server | |
$server->setClass('Crud'); | |
//start the SOAP requests handler | |
$server->handle(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment