jeudi 2 mars 2017

Web Server and Client Connection PHP PostgresQL

I am an automation test developer and hence have very minimum knowledge of web api development and Zero hands on experience. I am really in need of developing a Web API which has to add update or remove entries runtime.

What I understood till now from my research...

  • I need a Web Server (My case: Apache2)
  • I need a DB Server (My case: PostgreSQL)
  • I need to select a server side programming language (I chose PHP)
  • Front end can be html/php with Javascript

I have browsed through many websites, but failed to finding a proper guidance. My question:

Q: I need to have my submit button (btnShow) invoke a PHP method (showCustomerInfo() inside a seperate PHP file), which would send a request to server, to interact with DB (Select * from Customers where CustName = 'XYZ') and display on my client index.php.

My Code:

**Index.php

<form method="POST" action="showCustomer.php">
 <input type="text" class="customerName" name="customerName" />
 <div class="actions">
    <input type="submit" value="Show" name="btnShow" class="btnShow" />
 </div>
 </form>

showCustomer.php

include_once 'apicaller.php';

if(isset($_POST['btnShow']))
{
    read_Customer();

}

 public function read_Customer()
    {
        session_start();
        $apicaller = new ApiCaller(APPID, APPKEY, APP_URL);
        return $apicaller;
        $new_item = $apicaller->sendRequest(array(
            'controller' => 'Mycontroller',
            'action' => 'read',
            'name' => $_GET['name'],
            'contactNumber' => $_GET['contactNumber'],
            'address' => $_GET['address'],
            'license' => $_GET['license'],
            'username' => $_SESSION['username'],
            'userpass' => $_SESSION['userpass']
        ));

        header('Location: Mycontroller.php');
        exit();

    }

and then I have my code in my apicaller, controller and model to fetch data from DB using pg_connect and pg_query. But not sure how this connection between server and client works and how the retrieved data is shown on web page.




Aucun commentaire:

Enregistrer un commentaire