I want to connect to a mysql database using javascript.
If it is possible, how can I do this?
You could use AJAX to send a request to your server side script which will query the MySQL database. Javascript has no way of accessing a SQL database directly because it runs on the client. Imagine if this was possible: it would mean that anyone from his client computer would be able to send any SQL query he likes to your MySQL server which hopefully is not possible.
Related
I would like to know if it's possible to connecting a form to database (phpmyadmin) with Backbone ?
It's just to add emails newsletters.
Tks :)
PHPMyAdmin is not a database. It is an application used to access MySQL databases via a browser-based UI.
There are MySQL libraries for javascript being run from a server (like in node.js), but you do not want to be connecting to a database from your client. You would need an intermediary web service.
Running from a client would be extremely foolish in that you would a) have to open up database access from potentially any remote host in the world and b) you would have your database login credentials exposed to your clients.
I am looking for a way to save simple form data from a static web page without any server-side code. I've considered something like MongoLab via RESTful interface, but that would require including API credentials client-side and the saved data must be private. Any suggestions? Thanks.
you need to post you form data somewhere, so you must have a server listening for a http form submit, or alternatively use something like socket.io / WebSockets to send all the data to a server. You cannot write to a database from a user browser without contacting some server that will write the information to the database..
Hadn't thought of using a BaaS (back-end-as-a-service) provider like parse or stackmob, but that's the solution. Just hadn't thought of using it for a simple, static web page. I signed up for parse.com and was collecting data within five minutes!
I have a WebSQL database, and am trying to connect to a PHP script, and dump that database into another one on the server.
How do I format the javascript / jquery in order to do that correctly?
I guess I am asking, how do I dump all of my data in my tables into my PHP script, so that it can update and insert the data into another database on the server?
I have no clue where to even begin with this.
The terminology in this question is a little confusing. If you're trying to copy the database from one location to another on the same server, you would only use PHP at most. This could also be done with just your sql administration.
If you are attempting to copy the database to a "Web SQL" database on a client (not a server), I've found a round-a-bout sort of way to accomplish this. I say round-a-bout because in my case I had to copy the database from the server to local client files (aka cross domain). In short:
1) Use PHP to create a json_encode version of your database from the server, using fwrite to create a .json file on the server
2) Using a php proxy to deliver the json data, make a jquery ajax call to the proxy, for the .json file you created
3) Use javascript to store the JSON data into the client's "web sql" database.
I need to insert sample data into SQl server.
But i should use HTML,Javascript,JQuery,Ajax,XML only.
I can't use asp.net or php programming languages , because i will not use IIS for this project.
Is there any option to do this?
Hi,Is possible to connect to SQL from XML page.
You need to have a server side page to handle your ajax request where it will read the data coming from ajax request and send to the db.
If you do not want to use IIS, you can think about PHP as your server page which works on Apache server.
Is it possible to add a JavaScript variable in an SQL Server database database (run an SQL query or stored procedure)? If so, how?
With JavaScript only, no you cannot (unless you're using Node.js of course).
The point is, you'll need some server-side code to interact with your database. You can use JavaScript in the browser to make an Ajax call to a server-side script (PHP, Ruby, Python, ASP.NET, Node.js, etc.) that performs the interaction with the database.
You can not access the database from JavaScript. You need to send your data to PHP, Ruby on Rails or ASP.NET or whatever you are using to implement the back end.
You can use Ajax to post to a web service of some sort (or any other server side script) to pass the JavaScript value. The web service would access the database and save it...
Set value of variable in the hidden field and get value of that field at server side when submit form and save it into the database....
You can easily access a database from JavaScript in Node.js.
If you're doing it from the browser, you'll most definitely need some kind of mid-tier service which translates HTTP queries to the relevant database driver (you can write that in any language you want - PHP, JavaScript, ASP.NET, etc.).