Title: RemObjects, SOAP, PHP and Ajax
Question: If you want you buisness logic to stay in Delphi, but you want to allow access to your database over the Internet, this is one of the easy solutions.
Answer:
1. Start new VCL Standalone REM Object,
2. Add TROSOAPMessage fServerForm,
3. Add new service, for example:
function AryGetRecords(out HDim: Integer): TAryGetRecords;
4. This is my code in NewService_Impl:
function TNewService.AryGetRecords(out HDim: Integer): TAryGetRecords;
var
_pom: TAryGetRecords;
_i, _j: Integer;
begin
RODataSnapModule1.SQLConnection1.Open;
RODataSnapModule1.SQLQuery1.Open;
RODataSnapModule1.SQLQuery1.First;
HDim:=RODataSnapModule1.SQLQuery1.FieldCount;
_pom := TAryGetRecords.Create;
for _i := 0 to RODataSnapModule1.SQLQuery1.RecordCount - 1 do
begin
for _j := 0 to RODataSnapModule1.SQLQuery1.FieldCount - 1 do
begin
_pom.Add(RODataSnapModule1.SQLQuery1.Fields[_j].AsWideString);
end;
RODataSnapModule1.SQLQuery1.Next;
end;
result := TAryGetRecords(_pom.Clone);
FreeAndNil(_pom);
RODataSnapModule1.SQLConnection1.Close;
RODataSnapModule1.SQLQuery1.Close;
end;
I was connected to MS SQL Database
And that is all on Delphi side.
Now, start Delphi for PHP ;)
1. Download nusoap, from http://sourceforge.net/projects/nusoap/
2. And this little piece of code you need:
include("nusoap.php");
$soapclient = new soapclient("http://localhost:8099/soap", true);
$proxy = $soapclient-getProxy();
$result = $proxy-AryGetRecords();
$fieldCount = $result["HDim"];
I attached example of unit in PHP.