user1644208
user1644208

Reputation: 105

interfacing prolog with php and mysql

I am looking to see if this is a possible scenario -

My php page calls prolog (and sends the query with data), and then prolog code runs and binds certain (output) variables, and then I take these variables and then load it into mysql db.

ie,

PHP -> call and send data -> Prolog -> execute goal and bind output variables -> send output variables into mysql db

I have seen a lot of documentation on how to "generate" html pages using sicstus and swi etc.. but this is reverse of what i want to achieve. any pointers?

thanks!

Upvotes: 2

Views: 4558

Answers (3)

Erin
Erin

Reputation: 105

Based on my experience on previous projects where I had to connect PHP with Prolog I called Prolog from PHP using the php exec function:

exec("\"c:/program files/swipl/bin/swipl.exe\"" -f prolog_filename.pl -g your_query)

The exec function returns Prolog's output which you can you as you like(eg sending it to your mysql db).

You may need to edit the prolog path accordingly.

Upvotes: 2

CapelliC
CapelliC

Reputation: 60024

Calling SWI-Prolog from a Web server could be done as illustrated by J.Paine here, but the preferred way of run SWI-Prolog on server side is, well... as a Web Server.

This because is simpler to debug the logic and getting formatted output using the extensive libraries that SWI-Prolog offers.

There is always the possibility to write a PHP extension module, the underling language is the same C, but this is clearly a difficult path.

Upvotes: 0

Erik
Erik

Reputation: 2264

It's definitively possible to do what you're thinking about. For example

http://www.swi-prolog.org/pldoc/package/odbc.html

would allow you to work with a MySQL database from Prolog. However, I'm fairly certain that sending the output of your Prolog program back to php and then inserting it into mysql from the php side of things will make your life a whole lot easier.

Upvotes: 0

Related Questions