database entry through javascript - javascript

I'm need to know can i connect db through javascript? Actually, the last action where i end is done through javacsript. Now, i need to make some entries(extracted through javascript) in the database where last action stops. How can this be done?

The answer depends on where the Javascript being run.
If you're asking about Javascript running in a browser directly accessing a database on a remote server then the answer is no. The best you can do is create a web service which updates the Database and call that via an XMLHTTPRequest object from you JavaScript. You would need to be very careful about what you offered via such a web service. If you allowed any SQL statements anybody could connect to your service and run DELETE FROM customer; or insert new user records or do anything ghastly.
If you're running JavaScript through the Windows Scripting Host via CSCRIPT.EXE or similar you can create ODBC objects and access the database that way.
If you're running JavaScript on a JVM I think you can use JDBC.
If you want to give more details I can be more specific.

Related

Is it possible to run an SQL query on a local db file (not running on some server)?

I have some local.db file and just want to run some sql query on it. Do I need to run a localhost server and then somehow connect to it in order to run proceed? (This is for a simple client-side project with html,js,css)
#jimbob542 Thanks for suffering the game of 20 questions. Given that you are looking to access SQLite data from within an HTML using JavaScript, please refer to this SO answer
Is it possible to access an SQLite database from JavaScript? There are some limitations, but hopefully it will do what you need.

How can i connect JavaScript to a SQL server?

I work as an intern in a manufacturing company that designed a HTML web page run by JavaScript that is supposed to show real time statistics of the machine lines.
To do this it must connect to a SQL server in real time to obtain the data that it needs to display charts and reports.
I have good knowledge of other programming languages but I'm a rookie at JavaScript and I would like to know the safest way to do this, since the database contains sensitive data.
Can this be done?
You need some sort of middleman to connect to the database. Since you want to do this with JavaScript, I suggest you checkout NodeJS . You can then build a simple API that when consumed it will return the data required. One benefit of building an API is you will be able to consume it from the website that is already built without having to make any changes in the back end. You can simply use fetch the data from the front end using JavaScript.
Don't do this directly with Javascript in your HTML file in client-side(It is not secure).
Do this with any language that you know on the server side and read those data using ajax and display them in your HTML file.

Send form data to local workstation to initiate a Photoshop script with parameters from data

I have a large Photoshop script (written in Javascript) that accepts parameters from me and then generates unique software files and mockups to client specifications. What I would like to do is create a form on the company website for new clients to fill out and then when the form is submitted, have my Photoshop script execute automatically, thus eliminating the need for me to manually enter clients' custom parameters. What I am wondering is if it is at all possible to do this. I would need to somehow track the event as it goes to the server hosting the website and then relay that to my work station. Or, would I have to use my work station as the server (at least for the form)?
I am hitting a wall when it comes to online research so if you don't have an answer, but perhaps have a keyword I have yet to google, that would be appreciated too! Thank you for your time spent reading this.
Details on the "parameters:" The data that needs to be sent consists of Strings and Numbers only. While it is impersonal and does not need encrytion, it could (in some cases) be way to long to fit using the GET method.
Side note: My most current research has lead me to investigate JSON.
I am not sure if I understood your problem :) , but if your problem is to transfer information from server to local machine for processing you can try :
1) store the submitted form on server in file or db,
2) write another script on your local machine that will run every 10 minutes for example (you can do it via cron job in linux) which will grab the new inserted data from server and pass to your photoshop script or store in local machine.
Or you can do by nodejs, I mean
1) the script from local machine connects via socket to the server and listens for new events
2) after each new substitution from website the script receives data from socket and runs photoshop script with given parameters

Clientside PostgreSQL Javascript access without serverside part

I know that direct access to a database via Javasript is not recommended, since the user would get the database login and thus the ability to manipulate the database.
But in my case, the user cannot see the client-side code, since it's a phonegap app.
Is there a way to do it? And it not, what is a good way to do with a serverside part?
its really not recommened to access database from client-side its not only for security reasons, but what if you changed the database access or upgrade to different database, so you will have to change it in your app which you may not be able to access again after users installed if its mobile app and then you stuck to your database for ever,
so whatever you want to do you can add an action in server-side and depend on your params it will formulate your Query,
for example sending parameter for user=true this will search for users tables, sending parameter for account=true will search in users-accounts tables and so on.

Using a server to send/receive information between a mobile phone and web page

I am trying to set up a simple set up as follows:
Have a mobile app with a page consisting of 4 lines (4 html paragraph lines (I am using phonegap)).
I want to use a web page from which I will input the data for those 4 lines. This information is sent to a server and that server transfers this information to that app on that mobile phone. Now, those 4 lines on the mobile phone is filled with the new information.
Similarly user inputs information on another page consisting of 10 lines of li (list). This information is again sent to the server and to the web page where the information is displayed.
I can almost feel the "internet police guys" getting all hyped and ready to vote this question down. But please understand that I have been on this site and various forums desperate to find a tutorial to guide me to do this and not able to find.
I am trying to use ajax to perform this setup. Confused how I would be using the php file. Information such as password n username is going to go in that php file to connect to the server. But php is a server side script thus needs to sit at the public_html folder. How do I use the php file from my desktop? Write a separate javascript to access it?
It is the concept that is confusing me. I am familiar with html,js,php.
I would appreciate any guidance or maybe a link to a tutorial which would help me to do the concept I mentioned. Thanks for listening.
You will need to create an API using PHP. This API is uploaded to your server and is considered "RESTful". Google a tutorial for what fits your needs. You can set all sorts of rules in this API such as requiring any requests to have an ID or access token.
Since you are using PhoneGap, your HTML and JS files rest on the device, so you will need to allow permissions to your API from anywhere. For this you will have to speak to your host provider about unless you know how to configure it yourself (some providers restrict what you want to do by default as an extra security precaution against XSS attacks).
Next, you can either use jQuery, or you can write some AJAX calls by writing the JavaScript yourself.
The most efficient way for this to work is to send JSON objects to and from the API. You will include a "command" in the JSON when you are sending from your app. On the PHP side, you will retrieve this command and use the rest of the data included in your JSON object to process the request. Your API will need to encode a JSON object for return (such as a user's profile information).
Here is a basic PHP API tutorial to get you going that explains some of the features of a RESTful API: PHP API
Here is a simple AJAX function (you will probably want to make this much more modular): AJAX
As broad as your question is, it seems like the best/easiest thing for you to do will be for you to first create a PHP webpage that will access a SQL database to perform the record updating. Actually, this should serve all of your needs for your mobile users assuming you don't need push notifications for live data updates.
I am assuming, since you are using phone gap, that you are more comfortable with web languages. After you get the webpage fully operational, then you should start building your app based on that exact same SQL database. With mobile app development there are a lot more "what if's" (what if the phone rings, what if the app is running in the background, what if there is no cellular service, etc...)
It is always easier to start with what you know and build on that, rather than starting with a new development platform and troubleshooting as problems arise.

Categories

Resources