views:

465

answers:

9

I want to build an entire web app using only Javascript and MYSQL . Anyone know how I can go about this if it's possible. Thank you. p

A: 

You will not be able to use Javascript and MYSQL without using something such as PHP on the server side to bridge the gap between the database and the Javascript on the client side.

Edit: I may be wrong, however I have no idea how you would run Javascript on the server side.

teh_noob
The server can be any computer running any language.
Nosredna
+10  A: 

Try something like Jaxer, which will allow you to execute JavaScript on the Web Server and query databases.

Here are some syntax examples and usages:


Database, file, and socket access from JavaScript

alt text


Easily create RESTful JSON data services

alt text


Directly call server-side functions from the browser

alt text


Andreas Grech
@Dreas Grech: Jaxer was very interesting. +1
Kb
Indeed...It allows me to write a whole website with my current favorite language.
Andreas Grech
(July) Was it really worth bumping this old post with a trivial update to somebody else's old answer?
Marc Gravell
+2  A: 

If you can run javascript on the server, you can build a web-application with it (without the need for any other language like PHP etc.). Search the web for 'connection string mysql' to find out how to connect to your mySQL database and use ADO/ODBC. You'll need the MySQL ODBC-connector on the MySQL server.

Here's an example database connection (where MySQL server resides on the same server as the web server):

function connectDB()
{
   var connectStr = "DRIVER={MySQL ODBC 3.51 Driver}; " +
                    "SERVER=localhost; "                +
                 "PORT=[MySQL server port];"         +
                    "DATABASE=[your database]; "        +
                    "UID=[username];PWD=[password];"    +
                    "OPTION=3",
       conection  = Server.CreateObject("ADODB.Connection"); 

  //ERRID=>lib::connectDB::open
   try       {connection.Open(connectStr)             }
   catch(e)  {errAlert(e,'rs::connectDB','connection failed',1) }        
   return connection;
}

(Where errAlert is a custom function to return the error)

KooiInc
A: 

It's quite possible to write a web application using only javascript. One the key benefits of that is that since all code runs locally, you can make an application which doesn't require online connectivity.

The main detractor though, is that you can't hook it up to a database. But there are alternative data storage hacks you can use.

One example of such a javascript application is TiddlyWiki which is a personal wiki, contained in a single html file. The javascript application rewrites that html file, so you can carry it with you on a USB-drive or something.

Hans Sjunnesson
A: 

You could look at triplify which should expose your database as json and rdf. I haven't actually used this but I would imagine that would let you bypass writing any server side js and talk to the database directly in a language javascript understands, using an ajax request and json.

slashnick
A: 

You can build client-side applications in javascript, with an embedded database. HTML 5 has support for databases, and a couple of browsers have already implemented this part of the spec (safari, firefox with the gears plugin).

But this is only for clientside usage. You wont be able to share the database with other users. Also you can select which database you want to use. I think gears uses sqlite.

Andrej
+1  A: 

You could write your application entirely in client side javascript with AJAX / REST calls to your database server - using something like CloudKit on your server (or CouchDB, which features a native JSON HTTP interface). On the client side, Dojo or YUI abstract out a great deal of the IO handling…

Naum
+2  A: 

You can do it with Jaxer. There are some screencasts that'll get you started. Also check out project Phobos. Jaxer integrates nicely in Aptana studio, Phobos in Netbeans.

Vasil