views:

35

answers:

3

I'm working on a web application that's using CakePHP and MySQL. Depending on the circumstances, I may be using one of two computers and I may be behind a proxy server that won't allow me to directly modify any code on my web server. Because of this, I've installed XAMPP on my machines to act as a local web server, and I keep my code in an SVN respository I can still access from behind the proxy.

With the web server, I have three places this code might be executed from (although it will ultimately only be on the web server), and since I'm in development, I'm constantly modifying the database. To make it easier on me, I want to set all three copies of this application to use the web server database so I don't have to keep exporting and importing each time I modify the database.

When I try to access the database, the first error I get is "Unknown MySQL server host 'mysql.mywebsite.com'". I'm assuming this is because I have to use an http proxy for all internet access, and without it, it can't even resolve an address. Can I configure CakePHP or PHP or my local Apache or whatever to use the proxy server in order to access my database?

+2  A: 

Right off the jump, you need to get your database under source control. I would recommend the CakeDC Migrations plugin.

Getting this done will allow you to break the nightmarish cycle of phpMyAdmin importing/exporting (or, worse yet, MySQL CLI commands). If you take the time to do this now, it will save you a lot of time and grey hair in the future. Moreover, your site's database calls won't be subject to the latency of leaving your local machine, much less your local network.

If you want to keep a single, simple app/config/database.php configuration, you can use a fully-qualified URL for your database's hostname, and alter your development boxes' hosts file (full path in Windows: C:\Windows\System32\drivers\etc\hosts) to resolve the fully-qualified URL to 127.0.0.1. Thus, when you're on one of those boxes, Cake will end up connecting to your local database server, but will access the proper database server when you've deployed to your production web server.

Daniel Wright
+1 Wow! I didn't know about that one!
Leo
You make a lot of good points, but I was already versioning my database. That's part of the issue. I'll work on it in one environment, make changes to the database, create a build script and save it to source control. Then, when I work in another environment, I have to use the script I put in source control and rebuild that database. I want to use one database in all environments.
HenryAdamsJr
+3  A: 

Neither Cake nor PHP will talk directly to MySQL. That's handled by the low level mysql drivers. MySQL does provide their own proxy that you could try out.

Marc B
A: 

I tend to work either locally or on a hosted server. I find that using Netbeans I can work on the remote code without having to constantly upload and download.

Whatever system you use, the fewer instances you have the better. Keeping things in sync can very rapidly become a major headache.

Leo