Can I execute sql sentences in javacript without calling an external php file?
I have seen that I can use SQL with node.js easily but, I'm useing Vue.js and it's my first time so i'm a little bit confused.
In summary, I want to connect to a database without useing php and I don't know if it would work.
Thanks you!
if you want to develop only javascript, it is possible to use node.js server (alternative apache, nginx etc.)
For communication with db we can recommend framework Express and easy connect any sql
Related
I have a local site like no server no nothing just the html, css, javascript files and i need to send data from an app in my phone created with android studio and display it on the site.I read that you can have a webserver and send data with the android/java tcp client to it but i cant find how to do it.So how can i approach this?
This is possible using server-side programming languages.
You can receive data using Api and display it on your web pages after saving it in the database.
To start, I suggest learning Php - Mysql , it's easier to understand and easier to implement
you can send data from your android mobile to the server by using API such as REST and SOAP but you have to any of the server-side scripting languages like node PHP etc.. Please refer the tutorial point to get better ideas
https://www.tutorialspoint.com/android/android_php_mysql.htm
I've developed an application that I would like to use meteor.js for real time updates (I want to enhance but not change my program, for example when a user adds a comments make it update in real-time ) . Problem is meteor.js uses node.js (so javascript as server-side code). I use LAMP stack, Is it possible to get PHP to feed data into meteor.js from mysql.
Meteor is more than just an 'interactive webapplication'-builder or javascript framework. The idea is to have only one programming language (besides HTML/CSS for markup) to do all the work. Basically it creates a 'remote server' (in the clients browser) it can push data to and at the same time it publishes various API's to the users system. The data passed through these API's / connections has a specific structure which has to be adhered at all time.
Meteor is built around NodeJS, which makes it hard (if not impossible) to run it without this backend. Sure you can try to mimic the backend using PHP, but it would be a waste of time. Reading your question you'll be better of using a javascript framework like jQuery or Prototype. Unlike Meteor you will need to do the AJAX calls (POST & CallBack) yourself, but you can actually decide which backend you want to use yourself (including PHP / MySQL).
If you want to do this anyway you need to check the Meteor & NodeJS source code to see what the minimum requirements are to make Meteor run under PHP. The PHP stack has to interpret the commands Meteor sends and receivers, but this won't be an easy task.
You can use comet (or reverse ajax) for realtime updates.
Trying to marry node.js with PHP doesn't sound like a worthwhile path to go down. If someone insisted on using a system like Meteor.js, yet with a PHP back-end, it would make more sense to look at AngularJS which is mainly the client side.
Of course, that is different technology stack. If someone really insisted on the blending, one could consider using server side sockets to interact with PHP Web services; and/or use mongodb and/or mysql-node to interact with the same databases.
I released a meteorite package that interacts with a Wordpress site that has the Wordpress JSON API. A quick fix. For now.
Comes with a backend call that will return the raw data, or a publication that stores the posts using their id's instead of a randomly generated mongoid. And some basic templates to get you started including a Session variable that keeps track of the currently selected post.
I'm working on it a lot more and will eventually have a version that directly makes mysql calls from node so you won't need php or Wordpress; just the ability to access the mysql database (which can be remote, with the appropriate configuration, or on the same machine).
I have a Javascript application that requires two queries to a MS SQL Server database. I need this done as simply and lightly as possible, because this is a high speed application, with data refreshing constantly. I've read that there is only one (improper) way to do it (using ActiveX) directly and only through IE, and I'd rather do it properly with a server side language and have it work in Chrome. I am a Java programmer, but I'd rather avoid starting with connecting to Java if possible. Is there any other framework/server side language that can quickly, easily, and lightly connect to my database? I don't want my users to need to download any software or adjust their browsers, so something that I can just add to the folder with the web pages would be optimal. If you know of a good system, can you include a link to whatever needs downloading, a basic explanation of how to use it - limiting it to exactly what I need to make a basic select query, and why you think this system is the simplest, fastest option?
Thanks!
You might need to write some backend code in Python, NodeJs, C# or Java to create a Web API. Web API is a wrapper around your MS SQL so that you can apply access control and error handling logics.
C# has scaffolding projects for quickly create a Web API, but it's going to use Entity Framework, which has known performance issues.
NodeJs has a package for connecting with MS SQL, but you'll need to write custom code to wire it up with an HTTP server package such as Express JS.
You can't directly query a database using JavaScript. Even if you found an ActiveX workaround, you shouldn't do this. If a web client was able to directly access the filesystem either locally or on the server it would be a security nightmare.
If you want a web based client to a backend database you'll have to use some kind of server side scripting. If you're already familiar with Java then why not use a CGI script written in Java?
Disregard all answers telling you that's impossible. You can do it with javascript (however, it's really not recommended because of security matters) You should not connect to a database directly from the client browser, but if you need/want to do it, you can use ActiveXObject:
var conn = new ActiveXObject("ADODB.Connection"),
cString="Data Source=yourServer;Initial Catalog=yourCatalog;User ID=yourUserId;Password=yourPass>;Provider=SQLOLEDB";
conn.Open(cString);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("SELECT * FROM table WHERE id = 1", conn);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}
rs.close;
conn.close;
In the connection string, replace all words starting with your with your real value.
It is impossible to connect to a MS SQL database via JavaScript in a web browser. You would need back end code on a server to do that for you.
Let's say I wrote a little HTML site, deployed on my nginx webserver. I created a database with MongoDB and stored several million entries in it. The MongoDB server is only listening on the local interface and accessible via localhost:27017.
Now I want to go to my webpage on my publicly accessible nginx webserver and access the entries in the database via JavaScript, by clicking a button "Show Users" or "Get latest entries" and so on. I need to perform only simple read-only-queries on the database like counting, searching, aggregating, and so on, so I don't need write access.
How do you generally implement this? Do I really need to set up PHP, Python, and Java to access the DB or is it somehow possible to solve this by only using HTTP/REST Interfaces? Can NodeJS help me to solve this? Do I have to remove nginx when using NodeJS?
Sorry, but I'm quite confused with all that JavaScript/ NodeJS/ mongoose/ MongoDB/ JSON stuff.
You can keep nginx as server for static content like your html files. To serve dynamic data, use node.js to create a rest interface. The rest interface will provide the data it fetches from your MongoDb.
Since you have millions of entries in your database and do not require complex functionality I would recommend the mongodb-native-driver as node.js module.
On the client, use ajax to perform api calls to your created rest interface.
Mongoose is built on top of the native driver to allow object modeling.
I am working on a little fun project(webcalender) and I want to use mongoDB. MongoDB is running and I figured out how to deal with it. I also got the connection to PHP.
I was wondering is there any chance to connect to the MongoDB using simple javascript?
I have searched a lot and I always passed by Node.js? Do I need Node.js to connect to mongoDB over Javascript?
Does anyone have a great link? Tutorial? or arguments why I should not do that?
Thanks for help
there are client side ways of doing this but its not safe at all.
there are a few reasons for the lack of security.
1. connection info is in the source for anyone to see.
2. if you use a service like mongoHQ where its a restful API to connect to Mongo your secret is exposed on the client side.
Both of these reasons scared me enough to not use a JS library that allowed me to connect to mongo on client side.
is your application being built in node? or PHP?
if PHP I know theres a PEAR library for MongoDB, then you can use javascript on the client side to interact with php to do what you need on the DB.
if the application is being built in node.js then sure why not? I've had success using Mongoose with express in node.
hope that helps.
Yes, you need Node.js to access MongoDB via JavaScript, because simple plain JavaScript runs on the user browser, not on the server, and Node.js is meant to run on the server.
Accessing a database directly from the browser would be a huge security issue, since JS files are always available to those viewing the page.