简体   繁体   中英

Extracting mySQL data on same Domain using javascript

I am creating a web based app, and my mysql database is on the same domain as the web app. My question is can i directly access mysql database data using pure javascript. What i am trying to do is select all the data from a certain column and be able to randomly select 1 of the values from the column. Example COLUMN1 cat dog bear tiger random selection=dog

  1. If you want to access your mysql database directly from browser:

Answer: Not possible

  1. If you want to write some code in javascript which will run on server:

Answer: Possible

You can write very basic node.js code on your server, which is essentially pure javascript and then you can use any mysql plugin to connect to your database. Then you will need to expose a simple api, which you can call from your application.

My question is can i directly access mysql database data using pure javascript

Yes, as long as its serverside javascript (ie node.js). But I suspect you mean using clientside javascript. This is theoretically possible using asm.js but would require a huge amount of effort, and since most web delivered applications are designed around themodel of many clients accessing one server, this would mean exposing the dbms directly on the internet - which no sane person would ever do.

The closest common architecture pattern to what you are describing is a REST server providing an abstraction layer on top of a dbms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM