Skip to main content

Webservice Webclient with Mysqli

1) Example Get Data
server.php

<?php
require_once "../lib/nusoap.php";
$server = new soap_server();
$server->configureWSDL("mi primer ws","urn:mundopccmb");

if(!isset($HTTP_RAW_POST_DATA)){
    $HTTP_RAW_POST_DATA = file_get_contents("php://input");
}

function dataMahasiswa($id){
    $conn = mysqli_connect("localhost","root","","ws");
    $vehiculos = $conn->query("SELECT nim,nama,alamat FROM mahasiswa ");
    $ArrVehiculos = [];
    while ($vehiculo = mysqli_fetch_array($vehiculos,MYSQLI_ASSOC)) {
        $ArrVehiculos[] = $vehiculo ;
    }
    return json_encode($ArrVehiculos);
}

$server->register("dataMahasiswa",array("id"=>"xsd:int"),
                                    array("return"=>"xsd:string"),
                                    "urn:mundopccmb",
                                    "urn:mundopccmb#dataMahasiswa",
                                    "rpc",
                                    "encoded",
                                    "Carga todos los vehĂ­culos"
                  );

$server->service($HTTP_RAW_POST_DATA);


client.php:

<?php

require_once "../lib/nusoap.php";

$client = new nusoap_client("http://localhost/051001/mysqli/server.php?wsdl");
$vehiculos = $client->call("dataMahasiswa",array("id"=>10));
$vehiculos = json_decode($vehiculos);

echo "<table>";
foreach ($vehiculos as $vehiculo) {
    echo     "<td>".$vehiculo->nim."</td>
             <td> ".$vehiculo->nama."</td>
             <td>".$vehiculo->alamat." "."</td>";
}
echo "</table>";


2) Example Input Data

server_input.php

<?php
require_once "../lib/nusoap.php";
$server = new soap_server();
$server->configureWSDL("mi primer ws","urn:mundopccmb");

if(!isset($HTTP_RAW_POST_DATA)){
    $HTTP_RAW_POST_DATA = file_get_contents("php://input");
}

function insertMahasiswa($nim,$nama,$alamat){
    $conn = mysqli_connect("localhost","root","","ws");
    $sql = "INSERT INTO `mahasiswa` (`nim`, `nama`, `alamat`) VALUES ('$nim', '$nama', '$alamat')";
/*     $vehiculos = $conn->query($sql); */
    $vehiculos=mysqli_query($conn, $sql);
        if($$vehiculos==true){
            return "Employee inserted";
        }else{
            return "data not inserted";
        }

}

$server->register("insertMahasiswa",
                                    array("nim"=>"xsd:string", "nama"=>"xsd:string", "alamat"=>"xsd:string"),
                                    array("return"=>"xsd:string"),
                                    "urn:mundopccmb",
                                    "urn:mundopccmb#insertMahasiswa",
                                    "rpc",
                                    "encoded",
                                    "Carga todos los vehĂ­culos"
                  );

$server->service($HTTP_RAW_POST_DATA);


client_input.php

<?php
require_once "../lib/nusoap.php";
$client = new nusoap_client("http://localhost/051001/mysqli/server_input.php?wsdl");
?>
<form method="POST">
Nomor Mahasiswa :<input name='nim' required />
Nama Mahasiswa  :<input name='nama' required />
Alamat Asal     :<input name='alamat' required />
<input type='submit' value='simpan'/>

<?php

if(isset($_POST['nim']) and isset ($_POST['nama']) and isset ($_POST['alamat']) ){
$nim = $_POST['nim'];
$nama =$_POST['nama'];
$alamat = $_POST['alamat'];
//bisa and isset     */
$vehiculos = $client->call("insertMahasiswa",array("nim"=>"$nim","nama"=>"$nama","alamat"=>"$alamat"));

}

?>

Comments

Popular posts from this blog

Menggenerate nomor id

<?php //config $database = "dopo"; $tabel = "po"; $kolom_generate ="id"; $kolom_referensi = "id"; /* Database connection start */ $servername = "localhost"; $username = "root"; $password = ""; $dbname = $database; $mysqli = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error()); $q1 = "select * from $tabel order by $kolom_referensi DESC"; /* Database connection end */ echo '<table>'; // connect to the database // number of results to show per page $per_page = 10000; // figure out the total pages in the database if ($result = $mysqli->query($q1)) { if ($result->num_rows != 0) { $total_results = $result->num_rows; // ceil() returns the next highest integer value by rounding up value if necessary $total_pages = ceil($total_results / $per_page); // check if the 'page' variab...

Membuat Codeigniter PDF di CPANEL

1. Download FPDF dan copykan di folder application/thirdparty/pdf/ 2. Buat file Fpdf_gen.php di libraries. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Fpdf_gen { public function __construct() {  require_once APPPATH.'third_party/fpdf/fpdf-1.8.php'; define('FPDF_FONTPATH', APPPATH.'third_party/fpdf/font/'); $pdf = new FPDF(); $pdf->AddPage(); $CI =& get_instance(); $CI->fpdf = $pdf; } public function Footer() { $this->fpdf->SetY(-15); $this->fpdf->SetFont('Arial','I',8); $this->fpdf->SetTextColor(128); $this->fpdf->Cell(0,10,'Page ',0,0,'C'); } } 3. Buat file pdf.php di controller <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); defined('BASEPATH') OR exit('No direct script access allowed'); class Pdf extends CI_Controller {   public f...