Page 1 of 1

Database CRUD with JavaScript

Posted: Thu Nov 04, 2010 2:59 pm
by beandog
What do you guys do if you want to access your database directly, using JavaScript stuff (normally AJAX)? Using PHP as an intermediate layer, I mean.

I'm looking at building a REST API to access everything using AJAX, but I'm not sure if that's overkill or not, when I just need to get a few things.

Re: Database CRUD with JavaScript

Posted: Tue Nov 09, 2010 10:45 am
by saltwine
That does sound like overkill to me.

You only want to build an entire API if you want to expose access to functionality from a different domain.

If you're accessing your database on the same server, you just need some PHP scripts that will connect to your database, accept GET/POST data or retrieve the data you want, and optionally spit it out information as JSON.

Then if you're using a framework such as MooTools or jQuery, you can simply ping those scripts with GET/POST data and you've got all the CRUD you need!