How to insert data in DB with jQuery / Javascript without using PHP?

7

I'm learning Javascript and jQuery and am wanting to make a small website to test the insertion of data into a database. I have no knowledge in PHP, I would like to know if it is possible to insert data into a database only with Javascript or jQuery. I would also like to know the most efficient / practical way you recommend for this task.

    
asked by anonymous 30.01.2014 / 00:24

7 answers

3

You said in a comment :

  

What I want to do is something very simple to train some things like HTML5, CSS3 and javascript, I want to make a small "database" with names of movies I've already watched and the ones I still want to see.

If you are using a server

And I recommend you use one, look for a package like xampp.

Do you really want to make a MySQL database? Is it to learn how to handle SQL, or to make a dynamic website? For something like this I would forget the SQL and would use a json file on the server. You pull the file to JavaScript with jQuery ajax.

Sample file:

[
   { "titulo": "ET", ano: 1982 },
   { "titulo": "Indiana Jones", ano: 1981 }
]

If it's all local

You should be using a server.

In this case, create a JS file with a literal array:

var dados = [
   { titulo: 'ET', ano: 1982 },
   { titulo: 'Indiana Jones', ano: 1981 }
];
    
30.01.2014 / 03:08
15

Forget this idea. Accessing the database directly via javascript would create very serious security problems in your application, after all with a simple firebug, anyone could change the javascript or use the javascript console itself to put any SQL command, including a DROP DATABASE there. / p>

And before that, you would have to turn around in managing the database connection directly in the javascript, and that will not be easy, if at all.

In addition, even if you can get javascript to connect to the database, since javascript runs in the browser, you would have to expose the SQL server on a public network with the login and password being obtainable from the javascript. And then you have already given your database to any hacker on the internet to do whatever you want.

    
30.01.2014 / 00:30
3

Hello, I've seen this question and I thought, I think I know what he wants.

Well you do not want to create a complex and laborious back-end to do some trainings as you spoke, and from what I realized I would not like to use another language "World" for it.

I have a simple and elegant (quick) tip that does not hurt the application's security and works perfectly, NodeJS , for you who seem to be better acquainted with javascript, you'll be at home, simple learning curve and it's a great tool.

NodeJS works very well with MongoBD (a database oriented object with JSON data) and MySQL.

I recommend at least a look at the subject.

    
30.01.2014 / 02:57
2

You can work with data in MySQL using node.js which is a JavaScript on the server side . There is a very big fight between PHP and node.js on various performance issues. There you will study and try to enter this node world.

Follow a sample link using node.js with MySQL ...

link

    
30.01.2014 / 00:51
1

You can not use MySQL directly with javascript / jquery without a server-side script as they have already said.

But for simple use like yours, you can download a script like this REST-API and change the tables and fields you want to use: link The input and output format is JSON, easily used with jquery and all other MV frameworks (Backbone, Angular, etc.)

On top of that, learn to mess with REST, HTTP Requests, and the like.

    
30.01.2014 / 03:01
0

If you want to learn how to manipulate a database and return the result in HTML, I advise how the friends mentioned above first learn logic programming, then a server-side language (PHP, ASP.NET, JAVA, C #, PYTHON ...), since going to JSON, Node.JS will require good experience and knowledge of the subject in terms of web programming! Also in HTML5 is the IndexedDB, where you can manipulate in your own browser a database more simplistic, so you learn can be interesting. Here's a tutorial: link

I hope the content is useful to you!

Hugs

    
30.01.2014 / 20:36
-1

No, this is not possible JavaScript is a client-side usage language, so it is executed in the user's browser >, having no relation with the server. So you do not have direct access to the database.

Javascript is primarily used for the dynamic manipulation of content on the website through the browser and for the execution of requests.

    
30.01.2014 / 00:29