Problem Calling Prolog from Php

0

I'm new to this forum and a little bit with the Prolog programming language. I am currently working on a project based on an Expert System with web interface, using SWI-Prolog, based on a contribution made in another forum ( link ) that talks about how to make a query to SWi-Prolog through Php code. By following the steps indicated in said forum I could successfully make the call of SWI-Prolog from Php, obtaining the corresponding message in the browser. When I went directly to consult the .pl file that I had done for my project, I could not get any answer on the screen. In my .pl file (It works correctly in the SWI-Prolog console) I make a call to an external database through odbc_connect, from where I obtain certain data that I then proceed to display in the browser. When doing certain tests, I noticed that when calling a .pl file from Php and that the query requires a connection to an external database, this will not be done, therefore, by not complying with one of the rules of the query , this will not return any response. Why does that happen? Is it not possible to make the query from Php to SWI-Prolog and this in turn consult an external database?

PS: I'm using Wampserver with local server.

Below is part of the code in Php and a Prolog test code, to which I ask and if the connection is made successfully it will show the "Hello" on screen (when testing it in the SWI-Prolog console it works correctly, just like in the Windows console).

index.php:

<?php 
if(!file_exists("Prueba2.pl")) die("No se puede localizar el archivo .pl, el 
directorio actual es: ".__DIR__);
$output = 'swipl -s Prueba2.pl -g "abrir_conexion." -t halt.';
print_r($output);
?>

Prueba2.pl:

abrir_conexion:-
odbc_connect('MSprolog',_,
             [user(root),
              password(''),
              alias(prolog),
              open(once)]),
              write('hola').
    
asked by Cesar Becerra 02.10.2017 в 00:29
source

1 answer

0

Dear,

Post all your code, or at least a minimal subpart of it where we can replicate the problem. There are dozens of reasons why this may not work and we are not going to play guessing games.

In principle I commented that I think that connecting prolog to a database, is a design error, every language is good for one thing and prolog is good for solving large recursion stacks through functional programming, you are using a sophisticated key cricket to nail a nail, the ideal would be that prolog receives an entry with all the data you need to operate, process them and return a result, and whoever calls prolog, the person in charge of collecting that information from whatever source. / p>

On the other hand, the prolog program can not be interactive, that is, it must function as a black box, where it receives a series of inputs and returns a series of outputs, without interacting with the user, with files, or with bbdd. In terms of perfomance, the time that is lost performing the invocations is compensated with the one that is saved by not performing these tasks in prolog. In terms of functionality, having all the prolog files programmed in this way, facilitates the creation of unit tests, the integration with other technologies and the debugging of failures.

I look forward to your full source code for a more accurate answer.

    
answered by 02.10.2017 в 17:04