Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
You have to be way more specific, describing your particular task and reasons led you to this odd question. –  Your Common Sense Jul 28 '10 at 10:48
add comment

7 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
For the purposes of speculation - aren't there some server-side JavaScript solutions that could possibly do this? –  middaparka Jul 28 '10 at 10:39
    
@middaparka: See my updated answer please. –  Sarfraz Jul 28 '10 at 10:46
    
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. –  Amir R. Jul 28 '10 at 10:50
    
@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 Jul 28 '10 at 10:55
add comment

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

share|improve this answer
add comment

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.
share|improve this answer
    
actually they will be remote databases. –  Amir R. Jul 28 '10 at 14:42
add comment

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.

share|improve this answer
    
This is simply not true. There are serveral server side implementations of JavaScript. Have a look at nodejs.org –  lnwdr Jul 28 '10 at 10:49
    
Can you provide an example of this? Please and thank you! –  Amir R. Jul 28 '10 at 10:51
add comment

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/

share|improve this answer
    
why does this need to access local memory? isn't it data on some sql server somewhere? –  Amir R. Jul 28 '10 at 14:55
    
As part of HTML5 specs offline db access is the functionality. By using it you can do all CRUD on local database. –  sohilv Jul 30 '10 at 4:32
    
This API provides access to a local SQLite database, not a remote MySQL database. –  Kragen Javier Sitaker Mar 22 '11 at 4:06
add comment

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

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.