0
votes

i have a site made using PHP and backend mysql. There is a prolog file (.pro extension) which I would like to integrate with this site.

My prolog source file can be queried like this -

myprolog(Input, Output).

So I give prolog Input, and it returns its result by binding it to Output.

I am expecting one of my php pages, says callprolog.php to query this prolog source file by passing the Input, and then store the result from Ouput into a php variable for further processing.

Implementations - PHP 5, MySQL, SWI Prolog.

Please let me know how to establish this connection betwen the php file and prolog source, pass/get data to/from prolog/php file.

Thank you!

1

1 Answers

2
votes

I have done some projects where I needed to establish a connection between a php and a prolog(.pl) file. This is how I did it: I used the php exec function like this:

exec(prolog_path -f $your_file_name.pro  -g your_predicate/query_goes_here)

What the above line of code does is define where your prolog bin file resides,tells prolog the name of the file that sould be consulted and then enters the desired query. So, in your case the above code line will look something like this:

exec("\"c:/program files/swipl/bin/swipl.exe\"" -f your_prolog_filename.pro -g myprolog(Input,Output))

You may need to alter the prolog path but that is how I achived the php-prolog connection. Please read how the exec function works in the link that I provided you.