views:

137

answers:

7

If possible, how can I get (and post) data from a mysql database using javascript? I know I can use php and other languages, but I just need to know if this is possible with javascript?

Thanks in advance.

+1  A: 

That's not possible with Javascript. I could not find this with server-side javascript too.

Not sure about your exact requirement, but you can use Ajax to interact with database though some server side language.

Sarfraz
For the purposes of speculation - aren't there some server-side JavaScript solutions that could possibly do this?
middaparka
@middaparka: See my updated answer please.
Sarfraz
I'm using the phonegap framework to make mobile apps using web programming languages. only html and javascript can be used, so I'm trying to see how I can make use of a mysql database when I can only use javascript.
amirrustam
@amirrustam: That is unfortunate then but is suspect there should be some way, you need to look the docs of phonegap framework or ask for their support.
Sarfraz
A: 

it is not possible, javascript is executed on the client.

you could make the javascript call something on the server (e.g. php script) that access the database though.

JohnSmith
This is simply not true. There are serveral server side implementations of JavaScript. Have a look at http://nodejs.org
Techpriester
Can you provide an example of this? Please and thank you!
amirrustam
A: 

If by Javascript you mean NodeJS on the server, this project might interest you http://github.com/sidorares/nodejs-mysql-native - however the answers above are correct if you are talking about Javascript running inside a browser or other container.

If you want to run a vanilla javascript (for the concurrency speed) inside your own engine, I recommend looking at NodeJS and then using the NodeJS MySQL Native Driver that I linked above.

http://github.com/sidorares/nodejs-mysql-native

Beaks
+1  A: 

Judging from the "iPhone" and "Android" tags, I guess, you are trying to access the local storage databases on these platforms.

  1. They don't use MySQL, but SQLite.
  2. How you access them from the mobile browsers is described in the W3C draft documents for the local storage: http://dev.w3.org/html5/webstorage/ for the local storage API or http://www.whatwg.org/specs/web-apps/current-work/multipage/section-sql.html#sql for the SQL API. It should be roughly the same API on iOS and Android since both of them use the Webkit browser engine.
Techpriester
actually they will be remote databases.
amirrustam
A: 

The Web SQL database API isn’t actually part of the HTML5 specification, but it is part of the suite of specifications that allows us developers to build fully fledged web applications, so it’s about time we dig in and check it out. Some examples are here

http://html5doctor.com/introducing-web-sql-databases/

sohilv
why does this need to access local memory? isn't it data on some sql server somewhere?
amirrustam
As part of HTML5 specs offline db access is the functionality. By using it you can do all CRUD on local database.
sohilv
A: 

Do remove the tags iphone and android from this question. the tags are not relevant.

And only with javascript you cant accompolish this task , GET and POST request can be handled only by server side scripting languages like php.

Refer : http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml

Webrsk
A: 

javascript can get database from server if use AJAX , only a way is AJAX

meotimdihia