You are not logged in.
Pages: 1
Hi
Can a Web Client written in PHP be able to use the 16 Server example to run SQL through the SOA Service on the Mormot Server?
If so, where do I find information to create this PHP code?
Offline
I think you need to write a mORMot client in PHP if the server has authentication.
If there is no authentication then you can use something like the following code.
Note : I don't have PHP now to test this code.
<?php
list($rseOleDB, $rseODBC, $rseOracle, $rseSQlite3, $rseJet, $rseMSSQL) = [0,1,2,3,4,5];
function _callFunction($funcName, $params){
$mServer = "http://www.your-server.com:888/root";
$opts = array(
'http' => array(
'method'=>"POST", 'header'=>"Content-Type: application/json; charset=UTF-8",
'content'=> json_encode($params)
)
);
$context = stream_context_create($opts);
$url = "$mServer/RemoteSQL/$funcName"; //Or $url = "$mServer/RemoteSQL.$funcName";
return @file_get_contents($url , false, $context);
}
function connect($engine, $aServerName, $aDatabaseName, $aUserID, $aPassWord){
return _callFunction("Connect", [$engine, $aServerName, $aDatabaseName, $aUserID, $aPassWord]);
}
function getTables(){
return _callFunction("GetTableNames", []);
}
function execute($aSQL, $aExpectResults, $aExpanded){
return _callFunction("Execute", [$aSQL, $aExpectResults, $aExpanded]);
}
?>
Offline
What we usually do with PHP or JavaScript clients, is the following:
1. Use interface-based services
2. Always communicate via https (over a nginx proxy with Let's Encrypt certificates)
3. Force full JSON objects for communication (instead of default JSON array which require a contract check) using TSQLRestServer.ServiceDefine(...).ResultAsJSONObjectWithoutResult := true
4. Define JWT authentication, using TSQLRestServer.JWTForUnauthenticatedRequest, and a dedicated interface for retrieving the JWT
5. Use Mustache template for API documentation generation (see the doc)
Then, any PHP or JS programmer would be able to connect using the documentation, via regular JSON + POST over HTTP.
Online
Pages: 1