PHP and Cocoa?

kainjow

Registered
Is there any way I could execute a PHP script from within a Cocoa/ObjC app? The PHP script would be local (like in the app's bundle) and just plain PHP text no compiled or anything. Is this possible? I know you can do Perl scripts.

This could make my apps much better.

Would I use NSTask? If so, what would be the terminal thingy I'd have to use?
 

aled

Registered
Is it possible to get cocoa to hit a website holding a php script and feedback the results?

Or better still is it possible to get Cocoa to interface with MySQL local and/or remote??

I would love to do MySQL with Cocoa, but I'm new to Cocoa and have no idea what to look for. I can use Cocoa and am learning new stuff all the time.

The MySQL think is for local / personal use only. I would like to create a website management tool with Cocoa for making website content management quicker. PHP is what I use now but I think some things would be faster to set up in Cocoa. Then just upload the MySQL database after it's edited / done.

Any leads would be appreciated.

I know Java applets can interface with MySQL. But Java is harder to work with than Cocoa and I want to concentrate on Cocoa.
 

michaelsanford

Translator, Web Developer
What would you want to do that for? From Entropy.ch: "PHP is a server-side, cross-platform, HTML embedded scripting language."

Ok, if you're using PHP as a module in Apache, no you can't.

If you're using the CGI version of PHP, which Mark can't build for OS X anyway, I think it may theoretically be possible...but I'm not convinced.

The reason you can do Perl scripts from within a Cocoa bundle is that perl has its own executable interpreter (/usr/bin/perl), while PHP does not. Similarly, you can include any shell script you want in a Cocoa bundle since it will just call the shell binary.
 

aled

Registered
PHP can't be run from within Cocoa.

It'd have to be a URL request and data sent back.

But I'd hope it would be possible to interface with MySQL. Java Applets can do it.

How do you run UNIX commands from Cocoa??

Since MySQL is UNIX command line anyway it should be possible for Cocoa to interface with UNIX and pull back MySQL data that way.

Anyone know any Cocoa > UNIX commands?
 

michaelsanford

Translator, Web Developer
All you have to do to run unix commands in a cocoa app is add a script.sh (or whatever name you want) ending with the shell name, written as any regular shell script, to your project bundle.

Then just call it in your program (I'm not sure on the exact method to call a shell script off-hand, just check through the examples.
 

kainjow

Registered
I currently use PHP scripts on my website to parse through HTML websites and stuff. It just would be easier if I could bundle these PHP scripts within my app. I could do it in Perl, but I don't know Perl enough to do what I do in PHP.
 

michaelsanford

Translator, Web Developer
I understand your perl reservations, I had the same feelings when I became quite proficient in PHP but still needed some (particularly command-line) functionality PHP didn't provide.

Perl's really not that hard ;) I picked up a Qué Perl5 complete command reference for 10$ at my university bookstore, and another manual on flow, and it's coming along pretty well.
 

aled

Registered
Thanks michaelsanford and kainjow.

I'm going to check out NSTask as soon as I've finished my final exams next week.

We were bombarded with Windows C++ in Borland C++ Builder - it's definitely a good IDE and all. But coming from that to Cocoa takes a bit of getting used to.

Programming was the only class I couldn't do in Mac OS X. I'm the only Apple user in the year. I hope some of my cool assignments will make people think Apple is good from now on. They were all so ignorant.

I can definitely see the benefits of Objective-C.
 
Top