View Full Version : php / mySQL in Dashcode?
Jan 20, 2011, 10:06 AM
Hi, is there a way of using php / mySQL in Dashcode?
Jan 20, 2011, 10:47 AM
As a web service, yes, directly, no
Jan 20, 2011, 11:03 AM
So for web service, do I just add PHP page in my project and can I still add Library objects/parts etc within Dashcode?
what do you mean by directly?
Jan 20, 2011, 12:07 PM
You are not going to be able to put PHP in your project. What you can do is build a PHP page on a remote server and have the Dashcode connect it it via Ajax.
Jan 20, 2011, 04:54 PM
First things first. I've come to see Dashcode as a kind of rendering engine for web stuff but it's got much more than that in it. You can get it to serve php, the only problem being that you cannot directly preview the result of a php page being served in the editing mode. Most people get confused about that bit. It's 2 different things.
Happily you can test php in the built-in browser that launches when you build and run. You can of course edit the php code in the edit mode, but the preview just shows the un-served raw code.
To make it work, make sure that you have got php and MySQL running on your machine. I'm assuming you know how to do this?
The apache server does not need to be running, but it helps if you are going to be test publishing dashcode using your users Sites folder or if you have saved a php file there.
That being said you don't need to publish your site to test it in the built-in browser as long as php and MySQL are running on your machine.
Add your php file to your dashcode project and then build and run the project.
Your simulation browser will launch and hey presto the PHP file gets served when you call it just as if it had been served as one of the other commentators put it.
One word of warning - don't go around changing the .html to .php on files generated by dashcode, because that just breaks it. only use .php on files that you create / import.
Interestingly what I was doing was creating a php file to select a MySQL table and return a JSON result set to be used in a datasource. I found that I could just upload the necessary php files to a folder in my dashcode project and point the datasource to the path that would find them. That's the Web service bit, but I also had a web page that was also needed and this too worked in the browser simulator.
Jan 20, 2011, 05:13 PM
Why do you not just start the web server that is already installed on every mac? That can run as a PHP server if you want, and you can then edit your php in whatever you want.
In terms of the SQL databases, you can download an addon for Apache I think that allows you to run your mac as a database machine as well. And when you upload your code, as long as your database and php are on the same server you will not need to change anything as it still referenced through localhost.
Here is a link to start the PHP server: http://foundationphp.com/tutorials/php_leopard.php
Jan 20, 2011, 07:09 PM
thanks for all your help, I have a PHP website setup already, I have been reading about HttpRequest Ajax too,
so I can add a PHP page to my Dashcode project linked to my live site?
Jan 20, 2011, 07:31 PM
I just added a PHP page to my project with <? echo 'hello'; ?> and navigated to it, nothing happened?! hmm well, it turned out blank!