I have a php script who access a MySQL database, all running in my server. I know how to compile php scripts in order to generate a .exe program, but this is the first time I got a php script that uses a MySQL, and I dont know how to compile the entire think. I dont want the .exe to use a remote mysql because I need to use it offline.
Thanks for any help.
If you use PDO you might just switch to SQLite on the fly.
No, it is not possible to embed a MySQL server in a compiled PHP script. The best you will be able to do is either replace MySQL with something like SQLite (not sure how feasible that will be) or build an installer that ships MySQL and the appropriate database tables (much more feasible).
Related
So I have this php program that I can run on my computer locally using WAMP. However, I would want it to be accessed by another person in his own computer. Some of the things I've read include dealing with the IP address. However, in my specific situation, I think it would be better to turn it into an executable file (php + the mysql database I used).
Is it possible? If yes, how?
If not, what is the best or easiest way for it to be accessed by, for example, a client.
There is no .exe natively with PHP. PHP does support PHAR archives that are executable and you can use an SQLite database which is portable.
This is what you will see with applications like Composer.
http://php.net/manual/en/intro.phar.php
just create an executable program with vb or something, then connect it to the database,,,
I took a PHP course on a site called Codecademy.com, and I later learned that you needed a server to practice PHP independently. I don't want to host a server, because all I want to do is practice PHP. Why is this so?
Your need for a "server" is really just a need for some kind of PHP runtime. Since version 5.4, PHP includes an integrated webserver for you to do just this kind of thing, so as long as you install a recent version of PHP you have everything you need.
What You need to understand is that PHP is server-side.
That means if You open a php file without a server,
you will see the code, and not the result of php,
because PHP must be processed by PHP parser.
That's why You have to use a server, but You can open one locally, using a program such as:
XAMPP
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!
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.
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.
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.
How can I access my php script from a Python script?
I need my Python script to be able to access the variables within the php script. (By the way, I'm new to php and Python.)
Thanks in advance.
If I understand it correctly, you have a service in PHP, and want to communicate with another one in Python.
Now, this is not really related to PHP or Python: this is quite a classic issue of integration and there are several ways to accomplish it; without more details about your problem, it may be very difficult to be specific about a solution and what kind of approach could be the better for you, but below you can find some ideas.
You could for instance save the status from PHP service in an ad-hoc table in the database, and then query it from the Python service.
Another way could be to use a RESTful approach: the information is available as a resource, accessible via a GET query; in PHP you would have a small handler that would just return a small JSON (or XML, if you like that kind of stuff), and in Python you would have instead the client. Of course, there are security issues to consider, but I think you got the idea.
For more information, I recommend you having a look at an interesting series written some time ago by Paul Stovell about integration. It is very accessible, and shows several approaches - although not all of them apply to your current issue.
Elaborate. Is the PHP file local? On a webserver? Where's the python file?
If the php file is on a server with the python file, use an exec statement.
If the python file is local and the php file is on a server, then you need to use urllib.
If both are local, write an interpreter...
I am currrently making queries to my SQL Server using SQLCMD and I run this from PHPs exec() function. I was hoping to clarify that this isn't as efficient as the driver for SQL Server for PHP: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx. I am not sure if this is the same as http://us3.php.net/manual/en/book.mssql.php?
I find that everytime I run an exec command it is quite a slow response and I was hoping to get this confirmed before I move to this new driver and implement it. Is there a performance difference using this Driver rather than using the exec function to launch SQLCMD?
I know this is a bit fluffy, but I really appreciate help on this decision.
Thanks all
Ugg, yeah, get rid of your exec and use the php client library. You also won't have to deal with parsing your result sets back off the command line.
Launching another command, using exec or one of the other Program execution Functions, takes time ; using some PHP function/classes will probably always be faster -- and easier :
no need to launch another command
no problem for parameters passing
no parsing of the output : you'll get native PHP data as output
less problems like "command not found", or differences between UNIX/Linux and Windows
no problem with safe_mode and the like
I would definitly go with using some function provided by a PHP extension, instead of using exec.
As a sidenote, in this specific case :
the SQL Server driver for PHP is currently only available on Windows platforms -- doesn't exist for Linux :-(
it's not available as a PDO driver : you have to use the specific sqlsrv_* functions